:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d2321;
  --muted: #66706c;
  --line: #e2ddd2;
  --accent: #1f6f5c;
  --accent-soft: #dcefe8;
  --accent-text: #ffffff;
  --rec: #d64545;
  --warn: #b7791f;
  --gold: #f2c14e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615; --surface: #1b201f; --surface-2: #242a28; --text: #e8ece9; --muted: #98a39e;
    --line: #2e3533; --accent: #4fb89a; --accent-soft: #1d3a32; --accent-text: #0d1513; --rec: #ef6b6b;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121615; --surface: #1b201f; --surface-2: #242a28; --text: #e8ece9; --muted: #98a39e;
  --line: #2e3533; --accent: #4fb89a; --accent-soft: #1d3a32; --accent-text: #0d1513; --rec: #ef6b6b;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: Vazirmatn, Tahoma, system-ui, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.75; font-size: 15px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: 1.4; margin: 0 0 .5em; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1.02rem; }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.top .icon-btn { margin-inline-start: auto; color: var(--muted); display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; }
.top .icon-btn:hover { background: var(--surface-2); }
.rec-badge { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--rec); font-weight: 500; }
.rec-badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--rec); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .75rem; padding: 4px 0; border-radius: 10px; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--accent); font-weight: 700; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }
.ltr { direction: ltr; unicode-bidi: isolate; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--rec); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=password], input[type=search], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

/* record */
.recorder { text-align: center; padding: 26px 16px; }
.rec-btn {
  width: 132px; height: 132px; border-radius: 50%; border: none; cursor: pointer; margin: 6px auto 14px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .15s;
}
.rec-btn:active { transform: scale(.96); }
.rec-btn svg { width: 46px; height: 46px; }
.rec-btn.on { background: var(--rec); box-shadow: 0 0 0 0 color-mix(in srgb, var(--rec) 50%, transparent); animation: ring 1.8s infinite; }
@keyframes ring { 70% { box-shadow: 0 0 0 22px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.meter { position: relative; height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; max-width: 360px; margin: 12px auto 6px; }
.meter > b { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); transition: width .08s; border-radius: 6px; }
.meter > b.speech { background: var(--gold); }
.meter > i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--muted); opacity: .6; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { font-size: .78rem; color: var(--muted); }
.meeting-live { display: flex; align-items: center; gap: 10px; background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; }
.feed .item { border-top: 1px solid var(--line); padding: 10px 0; }
.feed .item:first-child { border-top: 0; }
.clip { white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head h2 { margin: 0; flex: 1; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-grid .wd { text-align: center; font-size: .78rem; color: var(--muted); padding: 2px 0; }
.cal-day {
  min-height: 64px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: start; color: var(--text);
}
.cal-day:hover { border-color: var(--accent); }
.cal-day .n { font-weight: 700; }
.cal-day .g { font-size: .68rem; color: var(--muted); }
.cal-day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day.has { background: var(--accent-soft); }
.cal-day .dots { display: flex; gap: 3px; margin-top: auto; flex-wrap: wrap; }
.cal-day .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.cal-day .dots i.p { background: var(--gold); }
.cal-day .dots i.m { background: var(--rec); }
.cal-empty { visibility: hidden; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 4px; }
@media (max-width: 480px) { .cal-day { min-height: 52px; padding: 4px; } .cal-day .g { display: none; } }

/* day */
.timeline .t { display: grid; grid-template-columns: 54px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.timeline .t:first-child { border-top: 0; }
.timeline .time { font-weight: 700; color: var(--accent); font-size: .9rem; direction: ltr; text-align: end; }
.timeline details summary { cursor: pointer; list-style: none; }
.timeline details summary::-webkit-details-marker { display: none; }
.seg { margin: 6px 0; }
.seg b { color: var(--accent); margin-inline-end: 4px; }
.tag { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-inline-start: 4px; }
.tag.warn { background: #fdf0d9; color: var(--warn); }
.tag.meet { background: var(--accent-soft); color: var(--accent); }
audio { width: 100%; height: 36px; margin-top: 6px; }

.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.person { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
.person h3 { margin: 0; font-size: 1rem; }
.person .role { color: var(--muted); font-size: .86rem; }
.person .contact { margin-top: 6px; font-size: .9rem; }
.person .notes { margin-top: 6px; font-size: .86rem; }
.todo { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; }
.todo input { margin-top: 6px; width: 18px; height: 18px; accent-color: var(--accent); }
.todo.done span { text-decoration: line-through; color: var(--muted); }

/* markdown */
.md h2, .md h3, .md h4 { margin-top: 1.1em; }
.md h2:first-child, .md h3:first-child { margin-top: 0; }
.md ul, .md ol { padding-inline-start: 22px; margin: .4em 0; }
.md li.sub { margin-inline-start: 18px; list-style: circle; }
.md p { margin: .5em 0; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.tbl { overflow-x: auto; }
.md table { border-collapse: collapse; width: 100%; font-size: .9rem; margin: .5em 0; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: start; }
.md th { background: var(--surface-2); }

/* chat */
.chat { display: flex; flex-direction: column; min-height: calc(100vh - 190px); }
.msgs { flex: 1; display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.msg.user { align-self: flex-start; background: var(--accent); color: var(--accent-text); border-color: var(--accent); border-start-start-radius: 4px; white-space: pre-wrap; }
.msg.model { align-self: flex-end; border-start-end-radius: 4px; }
.msg.thinking { color: var(--muted); }
.composer { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; background: var(--bg); padding: 8px 0; }
.composer textarea { min-height: 46px; max-height: 160px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; cursor: pointer; font-size: .86rem; }
.chip:hover { border-color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.toast { position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100% - 32px); font-size: .9rem; }
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); color: var(--text); }
.list-row:first-child { border-top: 0; }
.notice { background: #fdf0d9; color: #6b4a12; border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
:root[data-theme="dark"] .notice, :root:not([data-theme="light"]) .notice { }
@media (prefers-color-scheme: dark) { .notice { background: #3a2f1a; color: #f0d9a8; } .tag.warn { background: #3a2f1a; } }
