/* The UI kit (app/lib/ui/kit.dart and friends), as CSS. */

/* ── Icons (Phosphor, the same fonts as the phone app) ──────────────────── */
.ph {
  font-family: "Phosphor"; font-style: normal; font-weight: normal; line-height: 1; display: inline-flex;
  align-items: center; justify-content: center; flex: none; speak: never; -webkit-font-smoothing: antialiased;
}
.ph.fill { font-family: "PhosphorFill"; }

/* ── Buttons (NButton: primary buttons are outlined, never filled) ────────── */
.btn {
  --btn-fg: var(--accent);
  --btn-edge: var(--accent);
  --btn-fill: transparent;
  --btn-press: rgb(var(--glow-rgb) / .22);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 14px; border-radius: var(--r-base);
  border: 1px solid var(--btn-edge); background: var(--btn-fill); color: var(--btn-fg);
  font-size: 14px; font-weight: 500; line-height: 1.3; white-space: nowrap;
  transition: background-color .12s, opacity .12s, box-shadow .2s;
  user-select: none; max-width: 100%; text-decoration: none;
}
/* Smaller buttons keep their look; the area around them still takes the tap. */
.btn::before { content: ""; position: absolute; inset: calc((44px - var(--tap)) / 2) 0; min-height: var(--tap); top: 50%; transform: translateY(-50%); left: 0; right: 0; }
.btn > span.lbl { overflow: hidden; text-overflow: ellipsis; }
.btn:active:not(:disabled) { background: color-mix(in srgb, var(--btn-press), var(--btn-fill)); }
@media (hover: hover) { .btn:hover:not(:disabled) { background: color-mix(in srgb, rgb(var(--glow-rgb) / .1), var(--btn-fill)); } }
.btn:disabled { opacity: .45; }
.btn.loading { opacity: 1; }
.btn.secondary { --btn-fg: var(--text); --btn-edge: var(--divider); --btn-press: rgb(var(--glow-rgb) / .14); }
.btn.ghost { --btn-edge: transparent; padding: 0 6px; }
.btn.tinted { --btn-fill: rgb(var(--glow-rgb) / .12); }
.btn.glow { --btn-fill: var(--bg); box-shadow: 0 0 32px -8px var(--glow); }
.btn.danger { --btn-fg: var(--danger); --btn-edge: var(--danger); }
.btn.ghost.danger { --btn-edge: transparent; }
.btn.expand { width: 100%; }
.btn.lg { height: 50px; font-size: 15px; }
.btn.xl { height: 52px; font-size: 16px; }
.btn.sm { height: 36px; font-size: 13.5px; padding: 0 12px; }
.btn .ph { font-size: 17px; }
.btn.sm .ph { font-size: 16px; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 1.6px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite;
}
.spinner.lg { width: 28px; height: 28px; border-width: 2px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.center-spinner { display: grid; place-items: center; padding: 48px 0; }

/* NCircleButton */
.circle {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--divider); color: var(--text);
  transition: background-color .12s, opacity .12s;
}
.circle::before { content: ""; position: absolute; inset: -2px; }
.circle .ph { font-size: 18px; }
.circle.primary { border-color: var(--accent); color: var(--accent); }
.circle.ghost { border-color: transparent; }
.circle.glow { background: var(--bg); box-shadow: var(--shadow-glow); }
.circle:disabled { opacity: .45; }
@media (hover: hover) { .circle:hover:not(:disabled) { background: rgb(var(--glow-rgb) / .08); } }
.circle:active:not(:disabled) { background: rgb(var(--glow-rgb) / .16); }
.circle.sm { width: 36px; height: 36px; }
.circle.sm .ph { font-size: 20px; }

/* NChip */
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 40px; padding: 6px 16px; border-radius: 999px;
  border: 1px solid var(--divider); color: var(--text); background: transparent;
  font-size: 14px; line-height: 1.2; text-align: start;
}
.chip.sm { min-height: 36px; font-size: 13.5px; }
.chip[aria-pressed="true"], .chip.on { border-color: var(--accent); background: rgb(var(--glow-rgb) / .14); color: var(--a200); }
@media (hover: hover) { .chip:hover { background: rgb(var(--glow-rgb) / .08); } .chip.on:hover { background: rgb(var(--glow-rgb) / .18); } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.hscroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-inline: 16px; scroll-padding-inline: 16px; }
.chips.hscroll::-webkit-scrollbar { display: none; }

/* NToggle + ToggleRow */
.toggle {
  position: relative; width: 44px; height: 26px; flex: none; border-radius: 13px;
  background: var(--n900); border: 1px solid var(--n700); transition: background .2s, border-color .2s;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--n500); transition: inset-inline-start .2s var(--ease), background .2s;
}
.toggle.on { background: var(--a800); border-color: var(--accent); }
.toggle.on::after { inset-inline-start: 20px; background: var(--a200); }
.toggle-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 0; text-align: start;
}
.toggle-row .txt { flex: 1; min-width: 0; }
.toggle-row .sub { display: block; font-size: 12.5px; color: var(--n400); line-height: 1.4; margin-top: 2px; }

/* NPillTabs: sections on a pill track, the selected one on an indigo pill with a glow. */
.pill-tabs {
  position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 4px; border-radius: 26px; background: var(--a900); border: 1px solid var(--divider);
}
.pill-tabs .pill {
  position: absolute; top: 4px; bottom: 4px; border-radius: 22px;
  background: linear-gradient(var(--section-glow), var(--section)); border: 1px solid var(--a700);
  box-shadow: 0 0 18px -8px var(--glow-45); transition: inset-inline-start .26s var(--ease);
}
.pill-tabs button {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 6px; border-radius: 22px; color: var(--n400); font-size: 13.5px; line-height: 1.2; text-align: center;
}
.pill-tabs button[aria-selected="true"] { color: var(--a100); font-weight: 500; }
.badge {
  min-width: 20px; padding: 2px 6px; border-radius: 10px; font-size: 11.5px; font-weight: 600; line-height: 1.3;
  text-align: center; color: var(--n400); background: var(--n900); border: 1px solid var(--n800);
}
button[aria-selected="true"] .badge { color: var(--a100); background: rgb(var(--glow-rgb) / .14); border-color: var(--a700); }
.badge.fresh { color: var(--bg); background: var(--accent); border-color: transparent; box-shadow: 0 0 10px -3px var(--glow-70); }

/* NSegmented */
.segmented { display: flex; border: 1px solid var(--divider); border-radius: var(--r-base); overflow: hidden; }
.segmented button { flex: 1; min-height: 44px; padding: 8px; font-size: 14px; color: var(--n300); border-inline-start: 1px solid var(--divider); }
.segmented button:first-child { border-inline-start: 0; }
.segmented button[aria-checked="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); background: rgb(var(--glow-rgb) / .06); }

/* NRadioRow */
.radio-row { display: flex; gap: 12px; align-items: flex-start; width: 100%; min-height: 48px; padding: 4px 0; text-align: start; }
.radio-row .dot {
  width: 16px; height: 16px; margin-top: 4px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--divider); display: grid; place-items: center;
}
.radio-row[aria-checked="true"] .dot { border-color: var(--accent); }
.radio-row[aria-checked="true"] .dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.radio-row .sub { display: block; font-size: 12.5px; color: var(--n400); line-height: 1.4; }

/* Rules fade to transparent over 48px at each end (a Nocturne signature). */
.rule { height: 1px; border: 0; margin: 0; background: linear-gradient(90deg, transparent, var(--divider) 48px, var(--divider) calc(100% - 48px), transparent); }

/* Small headings */
.section-label { font-size: 11px; color: var(--n400); letter-spacing: calc(.08em * var(--track)); text-transform: uppercase; line-height: 1.3; }
:root[lang="ar"] .section-label { font-size: 12.5px; text-transform: none; }
.kicker { display: inline-flex; align-items: center; gap: 8px; }
.kicker::before { content: ""; width: 18px; height: 2px; border-radius: 1px; background: var(--accent); box-shadow: 0 0 8px var(--glow); }
.kicker.no-dash::before { display: none; }

.tag {
  display: inline-block; padding: 3px 10px; border-radius: 6px; font-size: 11px; line-height: 1.45;
  letter-spacing: calc(.02em * var(--track)); background: var(--n800); color: var(--n100);
}
.tag.accent { background: var(--a800); color: var(--a100); }
.tag.outline { background: none; border: 1px solid var(--accent); color: var(--accent); }

/* ✦ + muted text (Khala's "why" lines) */
.sparkle-line { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--n300); line-height: 1.45; }
.sparkle-line .ph { color: var(--accent); margin-top: .2em; font-size: 14px; }

/* NField and the pill composer */
.field label { display: block; font-size: 12px; color: color-mix(in srgb, var(--text) 70%, transparent); margin-bottom: 5px; }
.input, .textarea {
  width: 100%; padding: 12px; border-radius: var(--r-base); border: 1px solid var(--divider);
  background: var(--surface); color: var(--text); font-size: 15px; line-height: 1.4; unicode-bidi: plaintext;
  transition: border-color .15s;
}
.textarea { resize: none; display: block; }
.input:focus, .textarea:focus { border-color: var(--accent); outline: none; }
.input::placeholder, .textarea::placeholder { color: var(--n500); }
.input.lg { font-size: 17px; padding: 14px; }
.field .helper { font-size: 12px; color: var(--n400); margin-top: 6px; line-height: 1.4; }
.counter { font-size: 12px; color: var(--n500); text-align: end; margin-top: 4px; }
.counter.near { color: var(--accent); }

.pill-input {
  flex: 1; min-width: 0; min-height: 46px; max-height: 120px; padding: 12px 16px; border-radius: 22px;
  border: 1px solid var(--divider); background: var(--surface); color: var(--text); font-size: 15px; line-height: 1.4;
  resize: none; overflow-y: auto; unicode-bidi: plaintext; field-sizing: content;
}
.pill-input:focus { border-color: var(--accent); outline: none; }
.pill-input::placeholder { color: var(--n500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-input:placeholder-shown { height: 46px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* NCard */
.card { padding: 14px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
.card.tinted { background: rgb(var(--glow-rgb) / .07); border: 1px solid var(--a800); box-shadow: none; }

/* LinkRow */
.link-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; text-align: start; color: var(--text); text-decoration: none; }
.link-row > .ph:first-child { font-size: 20px; color: var(--accent); }
.link-row .lbl { flex: 1; min-width: 0; }
.link-row .val { max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--n400); }
.link-row .chev { font-size: 16px; color: var(--n500); }
.link-row.danger, .link-row.danger > .ph:first-child { color: var(--danger); }
@media (hover: hover) { .link-row:hover .lbl { color: var(--accent); } }

/* TypingDots */
.typing { display: inline-flex; gap: 4px; padding: 10px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--a300); animation: dot 1.1s infinite; opacity: .25; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { transform: none; opacity: .25; } 40% { transform: translateY(-3px); opacity: 1; } }

/* ScreenHeader */
.header { display: flex; align-items: center; gap: 2px; padding: calc(var(--safe-top) + 6px) 12px 10px 16px; min-height: 60px; }
.header.back { padding-inline-start: 6px; }
.header.large { padding-top: calc(var(--safe-top) + 12px); }
.header .titles { flex: 1; min-width: 0; }
.header h1 { font-size: 17px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
.header.large h1 { font-size: 22px; line-height: 1.25; letter-spacing: calc(-.015em * var(--track)); }
.header .sub { font-size: 12.5px; color: var(--n400); line-height: 1.4; }
.header .actions { display: flex; align-items: center; gap: 4px; }

/* Khala's avatar and the Sofouw mark (images, swapped for day versions on the light palette) */
.orb { flex: none; width: 36px; height: 36px; background: var(--khala) center / contain no-repeat; }
.orb.glow { filter: drop-shadow(0 0 10px var(--glow-45)); }
.orb.thinking { animation: none; filter: drop-shadow(0 0 14px var(--glow-70)) brightness(1.08); transition: filter .6s; }
.mark { flex: none; width: 60px; height: 60px; background: var(--mark) center / contain no-repeat; }

/* Photos: the placeholder ground with the faint star pattern, and the blur the design puts on locked photos */
.photo {
  position: relative; overflow: hidden; background: linear-gradient(170deg, var(--photo-top), var(--a900));
  isolation: isolate;
}
.photo::before {
  content: ""; position: absolute; inset: 0; opacity: .5; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%23F3F5FE' stroke-opacity='.10' stroke-width='.8'%3E%3Cpath d='M20 6 34 20 20 34 6 20Z'/%3E%3Crect x='10' y='10' width='20' height='20'/%3E%3Cpath d='M0 0h3M0 0v3M40 0h-3M40 0v3M0 40h3M0 40v-3M40 40h-3M40 40v-3'/%3E%3C/g%3E%3C/svg%3E");
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}
:root[data-theme="light"] .photo::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%233B4290' stroke-opacity='.12' stroke-width='.8'%3E%3Cpath d='M20 6 34 20 20 34 6 20Z'/%3E%3Crect x='10' y='10' width='20' height='20'/%3E%3Cpath d='M0 0h3M0 0v3M40 0h-3M40 0v3M0 40h3M0 40v-3M40 40h-3M40 40v-3'/%3E%3C/g%3E%3C/svg%3E");
}
.photo .initial {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 1;
  font-family: "Inter", "IBM Plex Sans Arabic", sans-serif; font-weight: 500; color: var(--a200);
  text-shadow: 0 0 30px var(--glow-45);
}
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 2; opacity: 0; transition: opacity .25s; }
.photo img.ready { opacity: 1; }
.photo.locked img { filter: blur(22px); transform: scale(1.15); }

.avatar { border-radius: 50%; flex: none; }
.avatar.ring { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--glow), 0 0 20px -4px var(--glow-70); }

/* Bubbles (ui/bubbles.dart) */
.bubble { max-width: min(78%, 520px); padding: 10px 14px; font-size: 15px; line-height: 1.45; }
.bubble.theirs { background: var(--surface); border-radius: 18px 18px 18px 4px; align-self: flex-start; }
.bubble.mine { background: var(--a900); box-shadow: inset 0 0 0 1px var(--a800); border-radius: 18px 18px 4px 18px; align-self: flex-end; }
:root[dir="rtl"] .bubble.theirs { border-radius: 18px 18px 4px 18px; }
:root[dir="rtl"] .bubble.mine { border-radius: 18px 18px 18px 4px; }
.bubble.pending { opacity: .6; }
.bubble.failed { box-shadow: inset 0 0 0 1px var(--danger); }
.note-line { text-align: center; font-size: 11px; color: var(--n500); letter-spacing: calc(.12em * var(--track)); text-transform: uppercase; margin: 10px 0; }
:root[lang="ar"] .note-line { text-transform: none; font-size: 12px; }
.khala-tint {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-base);
  background: rgb(var(--glow-rgb) / .08); border: 1px solid var(--a900); font-size: 13.5px; color: var(--a200); line-height: 1.45;
}
.khala-tint .orb { width: 18px; height: 18px; margin-top: 2px; }

/* Composer: pill input + round send button */
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px calc(8px + var(--safe-bottom)); background: var(--bg); }

/* Toasts (snack bars) */
.toasts {
  position: fixed; inset-inline: 0; bottom: calc(84px + var(--safe-bottom)); z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px;
}
.toast {
  pointer-events: auto; max-width: 560px; width: max-content; padding: 12px 16px; border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 14px; box-shadow: var(--shadow-md);
  animation: toast-in .2s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 900px) { .toasts { bottom: 24px; } }

/* Sheets (bottom sheets on phones, dialogs on wide screens) and dialogs */
.scrim {
  position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .5);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .18s;
}
:root[data-theme="light"] .scrim { background: rgb(22 24 38 / .35); }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 20px calc(16px + var(--safe-bottom));
  animation: sheet-in .24s var(--ease); box-shadow: 0 -10px 40px var(--shadow);
}
.sheet::before { content: ""; display: block; width: 32px; height: 4px; border-radius: 2px; background: var(--n700); margin: 4px auto 14px; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: .6; } }
.sheet.list { padding-inline: 0; }
.sheet .sheet-item {
  display: flex; align-items: center; gap: 16px; width: 100%; min-height: 56px; padding: 0 24px; text-align: start; font-size: 15px;
}
.sheet .sheet-item .ph { font-size: 22px; color: var(--text); }
.sheet .sheet-item.danger, .sheet .sheet-item.danger .ph { color: var(--danger); }
@media (hover: hover) { .sheet .sheet-item:hover { background: rgb(var(--glow-rgb) / .06); } }
@media (min-width: 900px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 18px; max-height: calc(100dvh - 80px); padding-bottom: 20px; }
  .sheet::before { display: none; }
  .sheet { padding-top: 22px; }
  .sheet.list { padding-top: 8px; padding-bottom: 8px; }
}
.dialog {
  width: calc(100% - 48px); max-width: 420px; margin: auto; padding: 22px 22px 14px; border-radius: 14px; background: var(--surface);
  box-shadow: var(--shadow-md); animation: pop .18s var(--ease); max-height: calc(100dvh - 48px); overflow-y: auto; overscroll-behavior: contain;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.scrim.center { align-items: center; }
.dialog h2 { font-size: 19px; line-height: 1.25; margin-bottom: 8px; }
.dialog p { font-size: 14px; color: var(--n300); }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

/* Inline errors */
.error { color: var(--danger); font-size: 13.5px; line-height: 1.45; }
.error-row { display: flex; gap: 8px; align-items: flex-start; color: var(--danger); font-size: 14px; }
.error-row .ph { margin-top: 2px; font-size: 17px; }

/* Empty and failed states */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 28px; }
.state > .ph { font-size: 40px; color: var(--a600); margin-bottom: 4px; }
.state h2 { font-size: 18px; line-height: 1.25; }
.state p { color: var(--n400); font-size: 14px; max-width: 420px; }
.state .btn { margin-top: 10px; }

/* Utilities */
.row { display: flex; align-items: center; gap: 8px; }
.row.top { align-items: flex-start; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 0; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.pad { padding: 0 16px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.hidden { display: none !important; }
.dot-new { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--glow); flex: none; }

/* A tab's header (TabHeader), made like Khala's: round mark, name and live line, round buttons, hairline below. */
.tab-header { position: relative; flex: none; padding: calc(var(--safe-top) + 10px) 16px 10px; }
.tab-header::after { content: ""; position: absolute; bottom: 0; inset-inline: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--divider) 48px, var(--divider) calc(100% - 48px), transparent); }
.tab-header-in { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-inline: auto; }
.tab-header-mark {
  position: relative; flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
  background: var(--a900); box-shadow: inset 0 0 0 1px var(--a800); color: var(--accent);
}
.tab-header-mark .photo.fill { border-radius: 50%; }
.tab-header-titles { flex: 1; min-width: 0; }
.tab-header h1 { font-size: 16px; font-weight: 500; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-header-sub { font-size: 12.5px; color: var(--n400); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-header-sub .live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--glow); margin-inline-end: 6px; vertical-align: 1px; }
.tab-header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
@media (min-width: 768px) {
  .tab-header { padding-inline: 28px; padding-top: calc(var(--safe-top) + 12px); padding-bottom: 12px; }
  .tab-header-mark { width: 42px; height: 42px; }
  .tab-header h1 { font-size: 17px; }
  .tab-header-sub { font-size: 13px; }
}
