@import url("ui/tokens.css");

:root {
  --bg: var(--ksa-sea-mist);
  --card: #FFFFFF;
  --ink: var(--ksa-deep-current);
  --body: var(--ksa-storm-slate);
  --muted: #7A96A3;
  --line: var(--ksa-fog);
  --accent: var(--ksa-open-water);
  --accent-ink: #0B5654;
  --beacon: var(--ksa-beacon-saffron);
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-1: 0 1px 2px rgba(14,47,60,.08);
  --shadow-2: 0 6px 16px rgba(14,47,60,.10);
  --font: 'Archivo', 'Segoe UI', Arial, sans-serif;
  --serif: 'Source Serif 4', Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 13px; line-height: 1.45; }
button, input { font: inherit; }
a { color: var(--accent-ink); }

.app { display: flex; flex-direction: column; height: 100vh; min-width: 280px; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--ksa-deep-current); color: #fff; }
.topbar__brand { display: flex; align-items: center; gap: 10px; }
.topbar__mark { width: 22px; height: 24px; }
.topbar__title { font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.topbar__sub { font-size: 11px; color: var(--ksa-spray); }
.iconbtn { width: 28px; height: 28px; border: 0; border-radius: var(--radius-sm); background: transparent; color: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.iconbtn:hover { background: rgba(255,255,255,.12); }
.iconbtn svg { width: 18px; height: 18px; }

/* search */
.search { padding: 10px 14px 0; }
.search input { width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ksa-deep-current); }

/* tabs */
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 10px 14px 0; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; border: 0; background: transparent; color: var(--body); padding: 8px 10px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; font-weight: 600; font-size: 12px; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--beacon); }
.tab:hover { color: var(--ink); }

/* view */
.view { flex: 1; overflow: auto; padding: 14px; }
.section { margin-bottom: 18px; }
.section__title { display: flex; align-items: baseline; justify-content: space-between; font-size: 11px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--body); margin: 0 0 8px; }
.section__title a { font-weight: 500; letter-spacing: 0; text-transform: none; font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.grid--wide { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
.grid--list { grid-template-columns: 1fr; }

.tile { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; align-items: stretch; text-align: left; color: var(--ink); min-width: 0; }
.tile:hover { border-color: var(--accent); box-shadow: var(--shadow-1); }
.tile:focus-visible { outline: 2px solid var(--ksa-deep-current); outline-offset: 2px; }
.tile__img { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; display: block; background: #fff; border-radius: var(--radius-sm); }
.tile--wide .tile__img { aspect-ratio: 16 / 9; }
.tile--dark .tile__img { background: var(--ksa-deep-current); }
.tile__name { font-size: 11px; line-height: 1.3; color: var(--body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__badge { position: absolute; top: 6px; right: 6px; font-size: 9px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; background: var(--ksa-sea-mist); color: var(--accent-ink); padding: 2px 5px; border-radius: 999px; }
.tile--list { flex-direction: row; align-items: center; gap: 10px; }
.tile--list .tile__img { width: 56px; aspect-ratio: 1; flex: 0 0 auto; }
.tile--list .tile__name { white-space: normal; }
.tile__desc { font-size: 11px; color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 600; cursor: pointer; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-ink); }
.btn--secondary { background: #fff; color: var(--ink); border-color: var(--ksa-deep-current); }
.btn--ghost { background: transparent; color: var(--accent-ink); }
.btn--sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--ksa-deep-current); outline-offset: 2px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* detail panel */
.detail { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.detail__preview { background: var(--ksa-sea-mist); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; padding: 16px; margin-bottom: 12px; }
.detail__preview img { max-width: 100%; max-height: 180px; }
.detail__preview--dark { background: var(--ksa-deep-current); }
.detail h2 { margin: 0 0 4px; font-size: 15px; }
.detail p { margin: 0 0 8px; color: var(--body); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.chip { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--ksa-sea-mist); color: var(--body); border: 0; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ksa-deep-current); color: #fff; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.swatch { border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); background: #fff; cursor: pointer; text-align: left; padding: 0; }
.swatch__color { height: 44px; }
.swatch__name { font-size: 10px; padding: 5px 6px 1px; color: var(--ink); font-weight: 600; }
.swatch__hex { font-size: 10px; padding: 0 6px 5px; color: var(--muted); }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 11px; font-weight: 600; color: var(--body); }
.field input, .field select, .field textarea { height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink); }
.field textarea { height: auto; padding: 8px 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.hint { font-size: 11px; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 8px; font-size: 12px; }

/* assistant */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 360px; }
.chat__log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: var(--radius); line-height: 1.45; white-space: pre-wrap; }
.msg--user { align-self: flex-end; background: var(--ksa-deep-current); color: #fff; border-bottom-right-radius: 2px; }
.msg--bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 2px; }
.msg--sys { align-self: center; background: transparent; color: var(--muted); font-size: 11px; }
.msg table { border-collapse: collapse; font-size: 11px; margin: 6px 0; }
.msg td, .msg th { border: 1px solid var(--line); padding: 3px 6px; text-align: right; }
.msg th:first-child, .msg td:first-child { text-align: left; }
.chat__actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chat__composer { display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 10px; }
.chat__composer textarea { flex: 1; min-height: 40px; max-height: 120px; }
.chat__context { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ksa-riverstone); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* status + toast */
.statusbar { display: flex; justify-content: space-between; padding: 6px 14px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); background: #fff; }
.toast { position: fixed; left: 50%; bottom: 44px; transform: translate(-50%, 20px); background: var(--ksa-deep-current); color: #fff; padding: 8px 14px; border-radius: var(--radius-sm); font-size: 12px; opacity: 0; pointer-events: none; transition: opacity 120ms ease-out, transform 120ms ease-out; max-width: 90%; box-shadow: var(--shadow-2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast--error { background: var(--ksa-red-clay); }
.toast--ok { background: var(--ksa-kelp-green); }

.empty { color: var(--muted); text-align: center; padding: 40px 10px; }
.notice { background: var(--ksa-haze); color: var(--ksa-burnished-gold); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12px; margin-bottom: 10px; }
.skeleton { background: linear-gradient(90deg, var(--line) 25%, #fff 50%, var(--line) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); min-height: 84px; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) { .toast, .typing i, .skeleton { transition: none; animation: none; } }
