/* Amigo Netanya — Knowledge Management admin. No build step, no external assets. */

:root {
  --teal: #0E8C80;
  --teal-dark: #0B5E57;
  --coral: #F26F55;
  --sun: #F5B335;
  --sea: #1BA6C9;
  --cream: #FBF8F2;
  --white: #FFFFFF;

  --bg: var(--cream);
  --surface: var(--white);
  --surface-2: #F4EFE6;
  --text: #1F2A2A;
  --text-muted: #5D6B6A;
  --heading: var(--teal-dark);
  --border: #E4DDD0;
  --primary: var(--teal);
  --primary-hover: var(--teal-dark);
  --primary-contrast: #FFFFFF;
  --accent: var(--coral);
  --danger: #D2462B;
  --danger-bg: #FDEBE6;
  --warn: #9A6500;
  --warn-bg: #FDF1D8;
  --info: #0D7A96;
  --info-bg: #E1F4FA;
  --ok: #0B7A6F;
  --ok-bg: #DFF3F0;
  --neutral-bg: #EEEAE2;
  --code-bg: #F7F4EE;
  --diff-add: #E2F5EC;
  --diff-del: #FCE6E1;
  --focus: #1BA6C9;
  --shadow: 0 1px 2px rgba(11, 94, 87, .06), 0 2px 8px rgba(11, 94, 87, .05);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar: 236px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Hebrew", "Noto Sans Ethiopic",
    Arial, "Arial Hebrew", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101817;
    --surface: #172221;
    --surface-2: #1D2B2A;
    --text: #E6EEEC;
    --text-muted: #9DB0AD;
    --heading: #7FD3C9;
    --border: #2A3B39;
    --primary: #13A193;
    --primary-hover: #17B8A8;
    --primary-contrast: #FFFFFF;
    --danger: #FF8A73;
    --danger-bg: #3A2019;
    --warn: #F5C25A;
    --warn-bg: #352A12;
    --info: #6ACDE6;
    --info-bg: #11303A;
    --ok: #6FD6C9;
    --ok-bg: #133430;
    --neutral-bg: #24302F;
    --code-bg: #121C1B;
    --diff-add: #143326;
    --diff-del: #3A1D18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
h1, h2, h3, h4 { color: var(--heading); line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
p { margin: .25rem 0 .75rem; }
small, .muted { color: var(--text-muted); }
.small { font-size: .85rem; }
code, .mono { font-family: var(--mono); font-size: .85em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: .5rem; top: .5rem; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ brand */
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; min-width: 0; }
.brand img { height: 36px; width: auto; display: block; }
.wordmark { font-weight: 800; letter-spacing: .06em; color: var(--primary); white-space: nowrap; font-size: 1.05rem; }
.wordmark .divider { color: var(--sun); margin: 0 .3em; font-weight: 400; }
.brand-sub { font-size: .78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }

/* ------------------------------------------------------------------ layout */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.app-header .spacer { flex: 1; }
.user-box { display: flex; align-items: center; gap: .5rem; font-size: .85rem; min-width: 0; }
.user-box .who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 14rem; }
.btn.menu-toggle { display: none; }
.dropzone:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
blockquote { border-left: 3px solid var(--border); padding-left: .75rem; }

.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: calc(100vh - 56px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: .75rem .5rem; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--ok-bg); color: var(--heading); font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }
.nav .badge { margin-left: auto; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: .75rem .75rem .25rem; }

main { padding: 1.25rem; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: .75rem; margin-bottom: 1rem; }
.page-head .titles { flex: 1 1 260px; min-width: 0; }
.page-head h1 { overflow-wrap: anywhere; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.breadcrumb { font-size: .85rem; margin-bottom: .25rem; }

@media (max-width: 860px) {
  .btn.menu-toggle { display: inline-flex; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar.open { display: block; }
  .user-box .who, .user-box .chip { display: none; }
  .app-header { gap: .4rem; padding: .5rem .75rem; }
  .brand { overflow: hidden; flex: 0 1 auto; }
  .brand img { height: 30px; }
  .wordmark { font-size: .9rem; }
  main { padding: 1rem; }
  .brand-sub { display: none; }
}

/* ------------------------------------------------------------------ cards & grids */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; flex: 1 1 auto; }
.card.warn { border-color: var(--sun); background: var(--warn-bg); }
.card.danger { border-color: var(--danger); }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid > * { min-width: 0; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.split { display: grid; gap: 1rem; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.end { justify-content: flex-end; }

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); margin-bottom: 1rem; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem;
  box-shadow: var(--shadow); text-decoration: none; color: var(--text); display: block; border-top: 4px solid var(--primary);
}
a.tile:hover { border-color: var(--primary); color: var(--text); }
.tile .label { font-size: .8rem; color: var(--text-muted); }
.tile .value { font-size: 1.75rem; font-weight: 700; color: var(--heading); line-height: 1.2; }
.tile .sub { font-size: .8rem; color: var(--text-muted); }
.tile.warn { border-top-color: var(--sun); }
.tile.danger { border-top-color: var(--coral); }
.tile.info { border-top-color: var(--sea); }

dl.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: .3rem 1rem; margin: 0; }
dl.kv dt { color: var(--text-muted); font-size: .85rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ bars */
.bars { display: flex; flex-direction: column; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 38%) minmax(0, 1fr) 3.5rem; gap: .5rem; align-items: center; font-size: .88rem; }
.bar-row .bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-2); border-radius: 99px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--primary); height: 100%; border-radius: 99px; min-width: 2px; }
.bar-fill.sea { background: var(--sea); }
.bar-fill.sun { background: var(--sun); }
.bar-row .bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.bar-row.empty .bar-label { color: var(--danger); font-weight: 600; }

/* ------------------------------------------------------------------ chips & badges */
.chip {
  display: inline-flex; align-items: center; gap: .25rem; padding: .05rem .55rem; border-radius: 99px;
  font-size: .76rem; font-weight: 600; background: var(--neutral-bg); color: var(--text); white-space: nowrap;
  border: 1px solid transparent; line-height: 1.6;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.outline { background: transparent; border-color: var(--border); color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.badge {
  display: inline-block; min-width: 1.4rem; padding: 0 .4rem; border-radius: 99px; text-align: center;
  font-size: .75rem; font-weight: 700; background: var(--coral); color: #fff; line-height: 1.4rem;
}
.badge.warn { background: var(--sun); color: #3a2a00; }

/* ------------------------------------------------------------------ buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .45rem .9rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; min-height: 2.25rem; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: .2rem .55rem; min-height: 1.85rem; font-size: .85rem; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
.linkish { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; }

label { font-weight: 600; font-size: .88rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .85rem; min-width: 0; }
.field .help { font-size: .8rem; color: var(--text-muted); font-weight: 400; }
.field.inline { flex-direction: row; align-items: center; gap: .5rem; }
.fields { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"],
input[type="url"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .45rem .6rem; width: 100%; max-width: 100%; min-height: 2.25rem;
}
textarea { min-height: 5rem; resize: vertical; }
textarea.code, .code { font-family: var(--mono); font-size: .85rem; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--primary); }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
.checks label { font-weight: 500; display: inline-flex; gap: .35rem; align-items: center; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; min-width: 0; }
legend { font-weight: 700; color: var(--heading); padding: 0 .3rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: .75rem; }
.filters > * { flex: 1 1 160px; max-width: 280px; }
.filters .field { margin: 0; }
.filters .grow { max-width: none; flex: 2 1 220px; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; background: var(--surface); }
th, td { text-align: left; padding: .5rem .65rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .cell-title { font-weight: 600; overflow-wrap: anywhere; }
td.wrap { min-width: 16rem; overflow-wrap: anywhere; }
td.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------ text, diff */
pre.text {
  white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .92rem; background: var(--code-bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; margin: 0;
  max-height: 28rem; overflow: auto; unicode-bidi: plaintext;
}
pre.text.short { max-height: 12rem; }
pre.json { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: .8rem; margin: .25rem 0 0;
  background: var(--code-bg); padding: .5rem; border-radius: var(--radius-sm); max-height: 20rem; overflow: auto; }
.diff { font-family: var(--mono); font-size: .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 32rem; overflow: auto; background: var(--code-bg); }
.diff div { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0 .5rem; unicode-bidi: plaintext; }
.diff .add { background: var(--diff-add); }
.diff .del { background: var(--diff-del); }
.diff .hunk { color: var(--info); background: var(--info-bg); }
.diff .file { color: var(--text-muted); font-weight: 700; }

.finding { border-left: 4px solid var(--sun); background: var(--warn-bg); padding: .5rem .75rem; border-radius: var(--radius-sm); margin: .35rem 0; }
.finding .excerpt { font-size: .85rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.notice { padding: .6rem .8rem; border-radius: var(--radius-sm); background: var(--info-bg); color: var(--text); border-left: 4px solid var(--sea); margin: .5rem 0; }
.notice.warn { background: var(--warn-bg); border-left-color: var(--sun); }
.notice.danger { background: var(--danger-bg); border-left-color: var(--coral); }
.notice.ok { background: var(--ok-bg); border-left-color: var(--primary); }
.notice ul { margin: .35rem 0 0; padding-left: 1.2rem; }

details { margin: .25rem 0; }
summary { cursor: pointer; color: var(--primary); font-size: .85rem; }

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 3px solid transparent; padding: .55rem .85rem; font: inherit;
  font-weight: 600; color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--heading); border-bottom-color: var(--primary); }
.tabs button:hover { color: var(--text); }

/* ------------------------------------------------------------------ lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .6rem .25rem; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.select-list > li { padding: 0; }
.select-list button {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: .6rem .7rem; font: inherit;
  color: var(--text); cursor: pointer; border-radius: var(--radius-sm);
}
.select-list button:hover { background: var(--surface-2); }
.select-list button[aria-current="true"] { background: var(--ok-bg); box-shadow: inset 3px 0 0 var(--primary); }
.item-title { font-weight: 600; overflow-wrap: anywhere; }

.side-by-side { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) { .side-by-side { grid-template-columns: minmax(0, 1fr); } }
.side { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; min-width: 0; }
.side.preferred { border-color: var(--primary); box-shadow: 0 0 0 2px var(--ok-bg); }

.citation { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .75rem; margin-bottom: .5rem; }
.citation.mine { border-color: var(--sea); box-shadow: inset 3px 0 0 var(--sea); }
.answer-text { white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext; background: var(--surface-2); padding: .75rem; border-radius: var(--radius-sm); }

/* ------------------------------------------------------------------ upload */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.25rem; text-align: center;
  background: var(--surface-2); cursor: pointer;
}
.dropzone.over { border-color: var(--primary); background: var(--ok-bg); }
.file-list { list-style: none; padding: 0; margin: .5rem 0; font-size: .88rem; }
.file-list li { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .25rem 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ states */
.empty { text-align: center; padding: 1.75rem 1rem; color: var(--text-muted); }
.empty strong { display: block; color: var(--text); margin-bottom: .25rem; }
.loading { display: flex; align-items: center; gap: .6rem; color: var(--text-muted); padding: 1rem; }
.spinner { width: 1.1rem; height: 1.1rem; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ------------------------------------------------------------------ toasts */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 1000; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--primary);
  border-radius: var(--radius-sm); padding: .65rem .9rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
  display: flex; gap: .5rem; align-items: flex-start; overflow-wrap: anywhere;
}
.toast.error { border-left-color: var(--coral); }
.toast.warn { border-left-color: var(--sun); }
.toast .msg { flex: 1; white-space: pre-wrap; }
.toast button { background: none; border: 0; cursor: pointer; color: var(--text-muted); font-size: 1.1rem; line-height: 1; }

/* ------------------------------------------------------------------ dialog */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text);
  width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
}
dialog.wide { width: min(980px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(10, 30, 28, .45); }
dialog form, dialog .dialog-inner { padding: 1.1rem 1.25rem; }
dialog h2 { margin-bottom: .75rem; }
dialog .dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.secret-box { display: flex; gap: .5rem; align-items: stretch; }
.secret-box input { font-family: var(--mono); }

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(400px, 100%); }
.login-card .brand { justify-content: center; margin-bottom: .75rem; }
.login-card .brand img { height: 64px; }
.tagline { text-align: center; color: var(--text-muted); margin: 0 0 1rem; font-size: .9rem; }
.tagline span { display: block; }
.login-card h1 { text-align: center; font-size: 1.15rem; }
.login-card .btn { width: 100%; }
