/* KonAgro design tokens (blueprint: Design system). Light default; dark via
   prefers-color-scheme or data-theme="dark". Status colour is always paired
   with an icon or a word. */
:root {
  --bg: #F7F8F6; --surface: #FFFFFF; --surface-glass: rgba(255,255,255,.72);
  --border: #E3E6E1; --text: #141A17; --text-muted: #5B6660;
  --brand: #2F6B4F; --brand-text: #FFFFFF;
  --good: #1E7D4F; --warn: #B26A00; --bad: #C2362F;
  --good-bg: #E6F3EC; --warn-bg: #FBF0DF; --bad-bg: #FBE7E5;
  --focus: #1F5FBF;
  --radius: 8px; --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20,26,23,.06), 0 4px 16px rgba(20,26,23,.06);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pad: 16px; --row: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1412; --surface: #171D1A; --surface-glass: rgba(23,29,26,.72);
    --border: #2A322E; --text: #ECEFEC; --text-muted: #9AA59F;
    --brand: #5DB38A; --brand-text: #0F1412;
    --good: #4CC38A; --warn: #F0A43A; --bad: #FF6B61;
    --good-bg: #16291F; --warn-bg: #2E2414; --bad-bg: #321A18; --focus: #6EA8FF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1412; --surface: #171D1A; --surface-glass: rgba(23,29,26,.72);
  --border: #2A322E; --text: #ECEFEC; --text-muted: #9AA59F;
  --brand: #5DB38A; --brand-text: #0F1412;
  --good: #4CC38A; --warn: #F0A43A; --bad: #FF6B61;
  --good-bg: #16291F; --warn-bg: #2E2414; --bad-bg: #321A18; --focus: #6EA8FF;
  color-scheme: dark;
}
:root[data-density="compact"] { --pad: 10px; --row: 34px; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); font-variant-numeric: tabular-nums; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 1em; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- brand ---- */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--brand); display: inline-block; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--text-muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.icon-btn { border: 0; background: transparent; color: var(--text-muted); font-size: 24px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.linklike { border: 0; background: none; color: var(--brand); font: inherit; padding: 0; cursor: pointer; }

/* ---- forms ---- */
.field { margin: 0 0 16px; border: 0; padding: 0; }
.field label, .field legend { display: block; font-weight: 500; margin-bottom: 6px; }
.field input[type=text], .field input[type=email], .field input[type=tel], .field input[type=password],
.field input:not([type]), .field select, .filters input, .filters select, .copy-row input {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; }
.field.has-error input, .field.has-error select { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: 13px; margin: 6px 0 0; }
.field-error::before { content: "▲ "; }
.field-hint { color: var(--text-muted); font-size: 13px; margin: 6px 0 0; }
.code-input { font-size: 22px !important; letter-spacing: .3em; text-align: center; max-width: 220px; }
.radio, .check { display: inline-flex; align-items: center; gap: 8px; margin: 4px 16px 4px 0; font-weight: 400; cursor: pointer; }
.check.block { display: flex; margin: 6px 0; }
.radio-list { display: flex; flex-direction: column; }
.check-row { display: flex; flex-wrap: wrap; padding-left: 26px; }
.check-row[aria-disabled="true"] { opacity: .5; }
.copy-row { display: flex; gap: 8px; }

/* ---- banners, pills, toasts ---- */
.banner { padding: 10px 14px; border-radius: var(--radius-sm); margin: 0 0 16px; border: 1px solid transparent; }
.banner.good { background: var(--good-bg); color: var(--good); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad  { background: var(--bad-bg);  color: var(--bad); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; border: 1px solid var(--border); color: var(--text-muted); white-space: nowrap; }
.pill.good { color: var(--good); border-color: currentColor; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.pill.bad  { color: var(--bad);  border-color: currentColor; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.toast.good .toast-icon { color: var(--good); } .toast.warn .toast-icon { color: var(--warn); } .toast.bad .toast-icon { color: var(--bad); }
.toast-close { margin-left: auto; border: 0; background: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }

/* ---- auth pages ---- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 20px; }
.auth-foot { color: var(--text-muted); font-size: 13px; margin-top: 16px; }

/* ---- app shell ---- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 10px 20px;
  background: var(--surface-glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.context { display: flex; gap: 16px; flex: 1; min-width: 0; font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: var(--brand-text); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; }
.usermenu-panel { position: absolute; right: 0; top: 42px; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; }
.usermenu-panel a, .usermenu-panel .linklike { padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; text-align: left; }
.usermenu-panel a:hover, .usermenu-panel .linklike:hover { background: var(--bg); }
.usermenu-head { display: flex; flex-direction: column; padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.shell { display: grid; grid-template-columns: 200px 1fr; min-height: calc(100vh - 57px); }
.sidenav { border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { padding: 8px 12px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 500; }
.sidenav a:hover { background: var(--surface); }
.sidenav a.active { background: var(--surface); color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
.nav-sep { height: 1px; background: var(--border); margin: 8px 4px; }
.content { padding: 24px; min-width: 0; max-width: 1400px; }
.page-title { margin-bottom: 12px; }
.breadcrumb { font-size: 14px; color: var(--text-muted); margin-bottom: 8px; }
.subnav { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.subnav a { padding: 8px 12px; color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.subnav a.active { color: var(--text); border-bottom-color: var(--brand); }
.subnav-later { color: var(--text-muted); font-size: 13px; opacity: .7; padding: 8px 12px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.toolbar p { width: 100%; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card.narrow { max-width: 560px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.grid-2.wide-left { grid-template-columns: minmax(320px, 2fr) minmax(280px, 1fr); }
.empty-state { max-width: 560px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
.kv dt { color: var(--text-muted); } .kv dd { margin: 0; }
.steps { padding-left: 20px; } .steps li { margin-bottom: 12px; }
.qr { margin: 12px 0; } .qr img { background: #fff; padding: 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.key { word-break: break-all; }

/* ---- tables ---- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters input[type=search] { max-width: 320px; }
.filters select { width: auto; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); height: var(--row); vertical-align: middle; }
table.data thead th { position: sticky; top: 0; background: var(--surface); font-weight: 600; color: var(--text-muted); font-size: 13px; white-space: nowrap; }
table.data thead th a { color: inherit; text-decoration: none; }
table.data tbody tr:hover { background: var(--bg); }
table.data td.actions { text-align: right; }
table.data td.empty { text-align: center; color: var(--text-muted); padding: 32px; }
.matrix .role-col { text-align: center; } .matrix .role-col a { display: block; color: var(--text); }
.matrix td.cell { text-align: center; }
.matrix .yes { color: var(--good); font-weight: 700; } .matrix .no { color: var(--text-muted); }
.matrix tr.group th { background: var(--bg); color: var(--text); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.perm-group { border: 0; padding: 0; margin: 0 0 16px; } .perm-group legend { font-weight: 600; margin-bottom: 4px; }

/* ---- drawer ---- */
.drawer-host:empty { display: none; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15,20,18,.35); backdrop-filter: blur(2px); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0,0,0,.12); z-index: 50; display: flex; flex-direction: column; overflow-y: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.drawer-head h2 { margin: 0; }
.drawer-body { padding: 20px; }
.drawer-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }
.drawer-section { padding: 16px 20px 24px; border-top: 1px solid var(--border); }
.danger-zone { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border); }
.perm-preview { margin: 8px 0 16px; } .perm-preview summary { cursor: pointer; color: var(--brand); }
.perm-preview ul { padding-left: 18px; margin: 8px 0; font-size: 14px; }

/* ---- phone ---- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidenav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; }
  .nav-sep { display: none; }
  .content { padding: 16px; }
  .context, .usermenu-name { display: none; }
  .grid-2.wide-left { grid-template-columns: 1fr; }
  .btn { min-height: 44px; }
}
@media (prefers-reduced-motion: no-preference) {
  .drawer { animation: slide-in .18s ease-out; }
  @keyframes slide-in { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
