/* ============================================================
   Quatern Watcher — PWA theme. Mirrors the Android app's
   Color.kt (palette), Type.kt (scale) and Compose components.
   ============================================================ */

/* ---- Palette: dark (default) ---- */
:root,
:root[data-theme="dark"] {
  --bg: #0B0D12;
  --surface: #12151C;
  --elevated: #191D27;
  --border: #242A36;
  --hairline: #1B202A;
  --text: #ECE8DF;
  --muted: #9AA0AE;
  --faint: #636B79;
  --accent: #E8B24C;
  --on-accent: #1A1206;
  --unread: #E8B24C;
  --danger: #E0705C;
  --field: #191D27;
  --accent-08: rgba(232, 178, 76, 0.08);
  --accent-10: rgba(232, 178, 76, 0.10);
  --accent-14: rgba(232, 178, 76, 0.14);
  --accent-16: rgba(232, 178, 76, 0.16);
  --accent-45: rgba(232, 178, 76, 0.45);
  --accent-55: rgba(232, 178, 76, 0.55);
  --cta: linear-gradient(120deg, #F5D98B 0%, #E8B24C 55%, #C98A2E 100%);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ---- Palette: light ---- */
:root[data-theme="light"] {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --elevated: #F0ECE3;
  --border: #E7E1D6;
  --hairline: #EDE8DE;
  --text: #1A1D23;
  --muted: #5B6270;
  --faint: #9AA0AC;
  --accent: #B07E22;
  --on-accent: #FFFFFF;
  --unread: #C98A2E;
  --danger: #C0503C;
  --field: #F0ECE3;
  --accent-08: rgba(176, 126, 34, 0.07);
  --accent-10: rgba(176, 126, 34, 0.10);
  --accent-14: rgba(176, 126, 34, 0.12);
  --accent-16: rgba(176, 126, 34, 0.14);
  --accent-45: rgba(176, 126, 34, 0.40);
  --accent-55: rgba(176, 126, 34, 0.50);
  --cta: linear-gradient(120deg, #F5D98B 0%, #E8B24C 45%, #C98A2E 100%);
  --shadow: 0 8px 24px rgba(120, 100, 60, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }

/* Type scale (Type.kt) */
.t-hl-md { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; }
.t-hl-sm { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.t-title-lg { font-size: 17px; font-weight: 600; }
.t-title-md { font-size: 15px; font-weight: 600; }
.t-body-lg { font-size: 15px; font-weight: 400; }
.t-body-md { font-size: 14px; font-weight: 400; }
.t-body-sm { font-size: 13px; font-weight: 400; }
.t-label-lg { font-size: 14px; font-weight: 600; }
.t-label-md { font-size: 12px; font-weight: 500; }
.t-label-sm { font-size: 11px; font-weight: 500; }

.c-text { color: var(--text); }
.c-muted { color: var(--muted); }
.c-faint { color: var(--faint); }
.c-accent { color: var(--accent); }
.c-danger { color: var(--danger); }

/* ============================================================
   Layout
   ============================================================ */
#app { min-height: 100%; }

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Shell: content + bottom bar (compact) / side rail (wide) */
.shell { display: flex; min-height: 100dvh; }
.shell-content {
  flex: 1;
  min-width: 0;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
/* Side rail only on genuinely large screens (tablet landscape / desktop) — the
   min-height keeps a short, wide window (phone in landscape) on the bottom bar. */
@media (min-width: 840px) and (min-height: 480px) {
  .shell-content { padding-bottom: 0; }
}

.page {
  max-width: 720px;
  margin: 0 auto;
  /* landscape safe-areas: keep content clear of a notch on the left/right edge */
  padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  width: 100%;
}
@media (min-width: 600px) {
  .page { padding: 0 max(28px, env(safe-area-inset-right)) 0 max(28px, env(safe-area-inset-left)); }
}

.page-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 0;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.page-header .titles { flex: 1; min-width: 0; }

/* ---- Header round actions ---- */
.hbtn {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--text);
  position: relative;
  flex: 0 0 auto;
  transition: background .15s, border-color .15s;
}
.hbtn:active { background: var(--elevated); }
.hbtn svg { width: 20px; height: 20px; }
.hbtn .badge {
  position: absolute; top: 3px; inset-inline-end: 3px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); border: 1.5px solid var(--bg);
}

/* ============================================================
   Bottom navigation (compact)
   ============================================================ */
.bottombar {
  position: fixed; inset-inline: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  display: flex; justify-content: space-evenly; align-items: center;
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}
.navitem {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 14px;
  color: var(--faint);
}
.navitem .icon-wrap { padding: 4px 16px; border-radius: 12px; transition: background .15s; }
.navitem svg { width: 22px; height: 22px; display: block; }
.navitem .label { font-size: 11px; font-weight: 500; }
.navitem.active { color: var(--accent); }
.navitem.active .icon-wrap { background: var(--accent-14); }
.navitem.active .label { font-weight: 600; }

/* Side rail (wide) */
.siderail { display: none; }
@media (min-width: 840px) and (min-height: 480px) {
  .bottombar { display: none; }
  .siderail {
    display: flex; flex-direction: column;
    width: 244px; flex: 0 0 244px;
    background: var(--surface);
    padding: 24px 16px;
    /* clear a landscape notch on the leading edge */
    padding-inline-start: max(16px, env(safe-area-inset-left));
    gap: 6px;
    border-inline-end: 1px solid var(--hairline);
  }
  .siderail .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 24px; }
  .railitem {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 14px; border-radius: 14px;
    color: var(--muted); font-size: 15px; font-weight: 500;
  }
  .railitem svg { width: 22px; height: 22px; }
  .railitem.active { background: var(--accent-14); color: var(--accent); font-weight: 600; }
}

/* ============================================================
   Brand
   ============================================================ */
.wordmark { font-weight: 700; }
.wordmark .w1 { color: var(--text); }
.wordmark .w2 { color: var(--accent); }
.logo-img { display: block; object-fit: contain; }

/* ============================================================
   Buttons / inputs
   ============================================================ */
.gold-btn {
  width: 100%; height: 56px;
  border-radius: 16px;
  background: var(--cta);
  color: var(--on-accent);
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity .15s, transform .05s;
}
.gold-btn:active { transform: scale(0.995); }
.gold-btn[disabled] { opacity: .55; pointer-events: none; }
.gold-btn svg { width: 18px; height: 18px; }

.ghost-btn {
  width: 100%; height: 52px;
  border-radius: 14px;
  color: var(--muted); font-size: 14px; font-weight: 600;
  display: grid; place-items: center;
}

.field-label { color: var(--muted); font-size: 12px; font-weight: 500; padding: 0 4px 8px; display: block; }
.field {
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 14px;
  transition: border-color .15s;
}
.field:focus-within { border-color: var(--accent); }
.field.error { border-color: var(--danger); }
.field svg.lead { width: 20px; height: 20px; color: var(--faint); flex: 0 0 auto; }
.field input {
  flex: 1; min-width: 0;
  background: none; border: none; outline: none;
  color: var(--text); font-size: 15px;
}
.field input::placeholder { color: var(--faint); }
.field .toggle { color: var(--muted); display: grid; place-items: center; padding: 4px; }
.field .toggle svg { width: 22px; height: 22px; }
.ltr { direction: ltr; text-align: start; }

/* ============================================================
   Login
   ============================================================ */
.login {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  background:
    radial-gradient(1100px 700px at 100% 0%, rgba(245, 217, 139, 0.10), transparent 60%),
    var(--bg);
}
.login-scroll {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(40px + env(safe-area-inset-top)) 24px 40px;
  overflow-y: auto;
}
.login-form { width: 100%; max-width: 420px; }
.login .brand-center { display: flex; flex-direction: column; align-items: center; margin-bottom: 28px; }
.login .brand-center .logo-img { margin-bottom: 16px; }
.login .err { color: var(--danger); font-size: 13px; margin-top: 12px; }
.remember { display: flex; align-items: center; gap: 8px; margin-top: 16px; color: var(--muted); font-size: 14px; }
.checkbox {
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--faint); display: grid; place-items: center; flex: 0 0 auto;
}
.checkbox.on { background: var(--accent); border-color: var(--accent); }
.checkbox svg { width: 14px; height: 14px; color: var(--on-accent); }
.checkbox.on svg { display: block; }
.checkbox svg { display: none; }

/* Center the login form vertically when there's spare height (tablet/desktop);
   phones keep the top-aligned, scrollable layout so the keyboard never hides it. */
@media (min-height: 700px) {
  .login-scroll { justify-content: center; }
}

/* ============================================================
   Cards / lists
   ============================================================ */
.list { display: flex; flex-direction: column; gap: 12px; padding: 4px 0 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
}
.card.unread { border-color: var(--accent-45); }
.card.tappable { transition: border-color .15s, transform .05s; }
.card.tappable:active { transform: scale(0.995); }

.monogram {
  border-radius: 50%;
  background: var(--accent-16);
  border: 1px solid var(--accent-45);
  display: grid; place-items: center;
  color: var(--accent); font-weight: 700;
  flex: 0 0 auto;
}

.card-top { display: flex; align-items: flex-start; gap: 12px; }
.card-top .grow { flex: 1; min-width: 0; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp4 { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--unread); flex: 0 0 auto; margin-top: 5px; }

.snippet { margin-top: 12px; color: var(--text); opacity: .92; }
.card-foot { margin-top: 14px; display: flex; align-items: center; gap: 8px; }
.open-link { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; font-size: 14px; margin-inline-start: auto; }
.open-link svg { width: 16px; height: 16px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 8px;
  background: var(--elevated); color: var(--muted);
  font-size: 11px; font-weight: 500; max-width: 100%;
}
.tag svg { width: 13px; height: 13px; flex: 0 0 auto; }
.tag.accent { background: var(--accent-14); color: var(--accent); }
.tag .tag-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.iconbtn { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: var(--faint); flex: 0 0 auto; }
.iconbtn svg { width: 20px; height: 20px; }

/* Group row */
.grouprow { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 18px; }
.grouprow .grow { flex: 1; min-width: 0; }
.grouprow .tags { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

/* ============================================================
   Switch
   ============================================================ */
.switch { width: 52px; height: 32px; border-radius: 16px; background: var(--elevated); border: 1px solid var(--border); position: relative; flex: 0 0 auto; transition: background .15s, border-color .15s; }
.switch .knob { position: absolute; top: 3px; inset-inline-start: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--muted); transition: inset-inline-start .16s, background .16s; }
.switch.on { background: var(--accent); border-color: var(--accent); }
.switch.on .knob { inset-inline-start: 25px; background: var(--on-accent); }

/* ============================================================
   Chips (filter) / segmented control
   ============================================================ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border-radius: 10px;
  background: var(--elevated); border: 1px solid var(--border);
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.chip.on { background: var(--accent-16); border-color: var(--accent-55); color: var(--accent); font-weight: 600; }

.kwchip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 6px 7px 12px; border-radius: 10px;
  background: var(--accent-14); color: var(--accent); font-size: 14px; font-weight: 600;
}
.kwchip button { color: var(--accent); display: grid; place-items: center; border-radius: 50%; }
.kwchip svg { width: 16px; height: 16px; }
:root[dir="rtl"] .kwchip { padding: 7px 12px 7px 6px; }

.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--elevated); border: 1px solid var(--border); }
.segmented .seg { flex: 1; text-align: center; padding: 10px; border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 500; }
.segmented .seg.on { background: var(--accent-16); color: var(--accent); font-weight: 600; }

/* ============================================================
   Search bar / filter summary
   ============================================================ */
.searchbar { display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 14px; border-radius: 14px; background: var(--elevated); border: 1px solid var(--border); margin-bottom: 8px; }
.searchbar svg { width: 20px; height: 20px; color: var(--faint); flex: 0 0 auto; }
.searchbar input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text); font-size: 15px; }
.searchbar input::placeholder { color: var(--faint); }

.filter-summary { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: var(--accent-10); color: var(--accent); margin-bottom: 8px; }
.filter-summary svg { width: 16px; height: 16px; flex: 0 0 auto; }
.filter-summary .txt { flex: 1; font-size: 14px; font-weight: 600; }
.filter-summary .clear { font-weight: 600; padding: 2px 8px; border-radius: 8px; }

/* ============================================================
   Bottom sheet / dialog
   ============================================================ */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; opacity: 0; transition: opacity .2s; }
.scrim.show { opacity: 1; }

.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 61;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 8px 0 0;
  max-height: 88dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform .24s cubic-bezier(.2,.8,.2,1);
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.sheet.show { transform: translateY(0); }
.sheet-inner { padding: 8px 20px 0; }
@media (min-width: 600px) {
  .sheet { max-width: 520px; margin: 0 auto; border-radius: 28px; bottom: 16px; inset-inline: 16px; }
}
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 10px; }
.sheet h2 { font-size: 20px; font-weight: 600; margin: 4px 0 16px; }
.sheet .section-title { font-size: 15px; font-weight: 600; margin: 22px 0 10px; }
.sheet .section-title:first-of-type { margin-top: 0; }

.dialog {
  position: fixed; inset: 0; z-index: 61; display: grid; place-items: center; padding: 24px;
}
.dialog .box { background: var(--surface); border-radius: 24px; padding: 24px; max-width: 360px; width: 100%; box-shadow: var(--shadow); }
.dialog h3 { font-size: 17px; font-weight: 600; margin: 0 0 8px; }
.dialog p { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog .actions button { padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; }

/* ============================================================
   Empty / loader / message states
   ============================================================ */
.msgstate { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 40px 32px; }
.msgstate .badge { width: 72px; height: 72px; border-radius: 50%; background: var(--accent-10); display: grid; place-items: center; margin-bottom: 20px; }
.msgstate .badge svg { width: 32px; height: 32px; color: var(--accent); }
.msgstate h3 { font-size: 17px; font-weight: 600; margin: 0 0 8px; }
.msgstate p { color: var(--muted); font-size: 14px; margin: 0; max-width: 320px; }

.loader { display: grid; place-items: center; padding: 48px; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--accent-16); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.spinner.sm { width: 20px; height: 20px; border-width: 2px; border-color: rgba(0,0,0,.15); border-top-color: var(--on-accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Toast
   ============================================================ */
.qw-toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 18px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 80;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 90vw; text-align: center;
}
.qw-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.qw-toast.danger { color: var(--danger); }

/* ============================================================
   Misc
   ============================================================ */
.settings-block { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 18px; }
.settings-group-title { color: var(--faint); font-size: 12px; font-weight: 600; padding: 0 4px; margin: 24px 0 10px; }
.account-row { display: flex; align-items: center; gap: 14px; }
.signout {
  height: 54px; border-radius: 16px; border: 1px solid var(--accent-45);
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--danger); font-weight: 600; font-size: 14px; width: 100%; margin-top: 28px;
}
.signout svg { width: 20px; height: 20px; }

.editor-active-row { display: flex; align-items: center; gap: 12px; background: var(--elevated); border-radius: 14px; padding: 14px; }
.editor-active-row .grow { flex: 1; }
.kw-input-row { display: flex; align-items: center; gap: 6px; height: 52px; padding: 0 6px 0 14px; background: var(--elevated); border: 1px solid var(--border); border-radius: 14px; }
.kw-input-row input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text); font-size: 15px; }
.kw-input-row input::placeholder { color: var(--faint); }
.kw-add { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-16); color: var(--accent); display: grid; place-items: center; flex: 0 0 auto; }
.kw-add svg { width: 20px; height: 20px; }

.hint { color: var(--muted); font-size: 13px; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.spin-inline { display: inline-block; vertical-align: middle; }

/* pull-to-refresh affordance */
.ptr { text-align: center; color: var(--faint); font-size: 13px; padding: 10px; }

/* install hint banner */
.install-hint {
  margin: 10px 0; padding: 12px 14px; border-radius: 14px;
  background: var(--accent-10); border: 1px solid var(--accent-45);
  color: var(--text); font-size: 13px; display: flex; gap: 10px; align-items: flex-start;
}
.install-hint svg { width: 18px; height: 18px; color: var(--accent); flex: 0 0 auto; margin-top: 1px; }
.install-hint .x { margin-inline-start: auto; color: var(--faint); flex: 0 0 auto; }
