/* ============================================================
   World Clock — Time Zone Manager
   Modern, mobile-responsive styling with light/dark themes
   ============================================================ */

:root {
  --bg: #f1f5f9;
  --bg-grad-1: #eef2ff;
  --bg-grad-2: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --bg-grad-1: #0f172a;
  --bg-grad-2: #0b1120;
  --surface: #131c31;
  --surface-2: #1c2740;
  --border: #283449;
  --text: #e9eef7;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2));
  min-height: 100vh;
  line-height: 1.5;
  transition: background 0.3s ease, color 0.3s ease;
}

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(12px);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 48px; width: auto; object-fit: contain; }
.brand-icon { font-size: 28px; line-height: 1; }
.brand-title { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.brand-sub { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; }
.header-status { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-2);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; }
.status-pill.online .status-dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,0.18); }
.status-pill.offline .status-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,0.18); }
.status-pill.offline { color: var(--danger); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-size: 17px; line-height: 1;
  display: grid; place-items: center; transition: transform 0.15s, background 0.2s;
}
.icon-btn:hover { transform: translateY(-1px); }

/* ---------- Ad slots ---------- */
.ad-slot {
  margin: 16px 0; min-height: 90px; border: 1px dashed var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden;
}
.ad-label { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }

/* ---------- What's new box ---------- */
.whats-new-box {
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 8%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-top: 24px;
  box-shadow: var(--shadow);
}
.whats-new-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--primary);
  letter-spacing: -0.01em;
}
.whats-new-box p {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
  margin: 4px 0;
}
.whats-new-box p:first-of-type {
  font-weight: 500;
}

/* ---------- Cards / panels ---------- */
.main-content { padding-bottom: 32px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 14px; letter-spacing: -0.01em; }
.section-title.no-margin { margin-bottom: 0; }

.add-panel { padding: 20px; margin-top: 8px; }
.add-form { display: grid; grid-template-columns: 1.4fr 1.4fr auto auto; gap: 14px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.hint { font-size: 0.72rem; color: var(--text-muted); }

input[type="text"] {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 0.92rem; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }

/* Combobox dropdown */
.combo { position: relative; }
.combo-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  list-style: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); max-height: 280px; overflow-y: auto;
}
.combo-list li {
  padding: 10px 13px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px;
  font-size: 0.88rem; border-bottom: 1px solid var(--border);
}
.combo-list li:last-child { border-bottom: none; }
.combo-list li:hover, .combo-list li.active { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.combo-list li .tz-offset { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.combo-list .no-result { color: var(--text-muted); cursor: default; }

/* Color picker */
.field-color { min-width: 0; }
.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input[type="color"] {
  width: 46px; height: 44px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer;
}
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  transition: transform 0.12s; box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}
.swatch:hover { transform: scale(1.15); }
.swatch.selected { border-color: var(--text); transform: scale(1.1); }

/* Buttons */
.btn {
  font-family: inherit; font-weight: 600; border: none; border-radius: var(--radius-sm);
  cursor: pointer; transition: transform 0.12s, background 0.2s, opacity 0.2s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; padding: 12px 18px; font-size: 0.92rem; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 7px 12px; font-size: 0.8rem; }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 26px 0 14px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.count-badge {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 7px;
  background: var(--primary); color: #fff; border-radius: 999px; font-size: 0.78rem; font-weight: 700; margin-left: 6px;
}
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--text-muted); cursor: pointer; font-weight: 500; }
.toggle input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ---------- Clock grid ---------- */
.clock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

.clock-card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); overflow: hidden;
  border-left: 6px solid var(--accent, var(--primary));
  animation: cardIn 0.3s ease;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.clock-card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 80% at 100% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%);
}
.clock-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; position: relative; }
.clock-city { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; word-break: break-word; }
.clock-zone { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }
.clock-actions { display: flex; gap: 4px; flex-shrink: 0; }
.mini-btn {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-size: 13px; display: grid; place-items: center; color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.mini-btn:hover { background: var(--surface); color: var(--text); }
.mini-btn.del:hover { color: var(--danger); border-color: var(--danger); }

.clock-time {
  font-size: 2.5rem; font-weight: 800; letter-spacing: -0.03em; margin: 12px 0 2px;
  font-variant-numeric: tabular-nums; position: relative;
}
.clock-time .secs { font-size: 1.3rem; color: var(--text-muted); font-weight: 600; }
.clock-ampm { font-size: 1.1rem; color: var(--text-muted); font-weight: 600; margin-left: 4px; }
.clock-date { font-size: 0.85rem; color: var(--text-muted); position: relative; }
.clock-dst {
  margin-top: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: color-mix(in srgb, var(--accent) 70%, var(--text));
}
.clock-dst-next {
  margin-top: 2px;
  font-size: 0.77rem;
  color: var(--text-muted);
}
.clock-offset {
  display: inline-block; margin-top: 10px; font-size: 0.72rem; font-weight: 600; position: relative;
  padding: 3px 9px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.day-diff { color: var(--text-muted); font-weight: 500; margin-left: 6px; }

/* drag handle */
.clock-card.dragging { opacity: 0.5; }
.clock-card[draggable="true"] { cursor: grab; }

/* Empty state */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state.hidden { display: none; }
.empty-emoji { font-size: 3rem; margin-bottom: 8px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-state p { max-width: 420px; margin: 0 auto; font-size: 0.92rem; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 24px 0 40px; text-align: center; font-size: 0.85rem; }
.site-footer .muted { color: var(--text-muted); margin-top: 4px; font-size: 0.8rem; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120%);
  background: var(--text); color: var(--surface); padding: 12px 20px; border-radius: 999px;
  font-size: 0.88rem; font-weight: 600; box-shadow: var(--shadow); z-index: 100;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); max-width: 90vw;
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .add-form { grid-template-columns: 1fr 1fr; }
  .add-form .field-color { grid-column: 1 / -1; }
  .add-form #addBtn { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .add-form { grid-template-columns: 1fr; }
  .clock-grid { grid-template-columns: 1fr; }
  .clock-time { font-size: 2.2rem; }
  .brand-sub { display: none; }
  .toolbar { gap: 10px; }
  .toolbar-right { width: 100%; justify-content: space-between; }
}
@media (max-width: 380px) {
  .header-status #connectionText { display: none; }
}
