/* Ether Technology — Unified R&D Management System */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #16202e;
  --ink-2: #5b6b7f;
  --ink-3: #93a1b3;
  --line: #dde4ec;
  --navy: #16243a;
  --navy-2: #22344f;
  --accent: #2f7de1;
  --ok: #1f9d55;
  --warn: #d98207;
  --danger: #d23f3f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,32,46,.06), 0 4px 16px rgba(16,32,46,.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  --cls-unclassified: #1f9d55;
  --cls-confidential: #d98207;
  --cls-secret: #e2601c;
  --cls-topsecret: #d23f3f;
  --cls-sci: #7b4bc7;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141d;
    --surface: #151d29;
    --surface-2: #1b2534;
    --ink: #e7edf5;
    --ink-2: #a3b1c4;
    --ink-3: #6f8098;
    --line: #26334a;
    --navy: #0b111a;
    --navy-2: #151d29;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Chrome ---------- */

.banner {
  background: linear-gradient(90deg, var(--navy), var(--navy-2));
  color: #cfe0f5;
  text-align: center;
  font-size: .68rem;
  letter-spacing: .12em;
  font-weight: 600;
  padding: .4rem 1rem;
  border-bottom: 2px solid var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: .65rem; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-weight: 800; font-size: 1.05rem;
}
.brand h1 { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }
.version { font-size: .68rem; color: var(--ink-3); }

.tabs { display: flex; gap: .15rem; flex: 1; flex-wrap: wrap; }
.tab {
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: .84rem; font-weight: 500;
  color: var(--ink-2); padding: .45rem .7rem; border-radius: 7px;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.active { background: var(--accent); color: #fff; }

.user { display: flex; align-items: center; gap: .5rem; font-size: .78rem; color: var(--ink-2); }
.clearance {
  background: var(--cls-secret); color: #fff; font-weight: 700;
  font-size: .62rem; letter-spacing: .08em; padding: .2rem .45rem; border-radius: 4px;
}

main { padding: 1.5rem 1.25rem 4rem; max-width: 1500px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.view-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem;
}
.view-head h2 { font-size: 1.3rem; letter-spacing: -.02em; }
.actions { display: flex; gap: .5rem; }

/* ---------- Buttons ---------- */

.btn {
  font: inherit; font-size: .82rem; font-weight: 550;
  padding: .45rem .85rem; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn.tiny { font-size: .72rem; padding: .25rem .5rem; }

/* ---------- Stats ---------- */

.stat-grid {
  display: grid; gap: .85rem; margin-bottom: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow);
}
.stat .label { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 600; }
.stat .value { font-size: 1.65rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; }
.stat .value.warn { color: var(--warn); }
.stat .value.danger { color: var(--danger); }

/* ---------- Panels ---------- */

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.panel h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin-bottom: .75rem; }

.split { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.split .panel { margin-bottom: 0; }
.split + .split { margin-top: 1rem; }

/* ---------- Lists ---------- */

.list { display: flex; flex-direction: column; gap: .5rem; }
.row {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface-2); cursor: pointer;
}
.row:hover { border-color: var(--accent); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: .87rem; }
.row .meta { font-size: .74rem; color: var(--ink-2); }
.row.flat { cursor: default; }
.row.flat:hover { border-color: var(--line); }

.empty { color: var(--ink-3); font-size: .84rem; padding: .75rem 0; font-style: italic; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block; font-size: .65rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
  padding: .18rem .45rem; border-radius: 4px; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.badge.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.badge.accent { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.badge.cls { color: #fff; border: 0; }

/* ---------- Progress ---------- */

.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.slim { width: 90px; flex: none; }

/* ---------- Filters ---------- */

.filters {
  display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem;
  align-items: center;
}
.filters input, .filters select, .form-body input, .form-body select, .form-body textarea,
.login-card input {
  font: inherit; font-size: .84rem; padding: .42rem .6rem;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); color: var(--ink);
}
.filters input[type="search"] { min-width: 250px; flex: 1; max-width: 420px; }
.filters input:focus, .filters select:focus,
.form-body input:focus, .form-body select:focus, .form-body textarea:focus,
.login-card input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--ink-2); }

/* ---------- Project cards ---------- */

.card-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.pcard {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; display: flex; flex-direction: column; gap: .65rem;
  cursor: pointer; border-top: 3px solid var(--accent);
}
.pcard:hover { border-color: var(--accent); transform: translateY(-1px); }
.pcard h4 { font-size: .95rem; letter-spacing: -.01em; }
.pcard .code { font-family: var(--mono); font-size: .7rem; color: var(--ink-3); }
.pcard .obj { font-size: .81rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard .tags { display: flex; gap: .3rem; flex-wrap: wrap; }
.pcard .foot { display: flex; justify-content: space-between; font-size: .73rem; color: var(--ink-2); }

/* ---------- Tables ---------- */

.table-wrap {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th {
  text-align: left; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-3); font-weight: 700;
  padding: .7rem .8rem; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }
td .cell-actions { display: flex; gap: .3rem; }

.chip-list { display: flex; gap: .45rem; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); border-radius: 99px;
  padding: .3rem .7rem; font-size: .76rem; background: var(--surface-2);
}
.chip b { font-weight: 650; }

/* ---------- Charts ---------- */

.chart-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.chart-grid .panel { margin-bottom: 0; }
.chart-grid canvas { max-height: 240px; }

/* ---------- Modal ---------- */

.modal-backdrop, .drawer-backdrop {
  position: fixed; inset: 0; background: rgba(10,16,24,.5);
  z-index: 90; display: grid; place-items: center; padding: 1rem;
  backdrop-filter: blur(2px);
}
/* `display:grid` above outranks the UA [hidden] rule, so restate it here —
   otherwise the dismissed backdrops sit invisibly over the page and eat clicks. */
.modal-backdrop[hidden], .drawer-backdrop[hidden] { display: none; }
.drawer-backdrop { place-items: stretch; justify-content: flex-end; padding: 0; }

.modal {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  width: min(620px, 100%); max-height: 88vh; display: flex; flex-direction: column;
}
.drawer {
  background: var(--surface); width: min(560px, 100%);
  height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal header, .drawer header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--line);
}
.modal header h3, .drawer header h3 { font-size: .98rem; }
.close { border: 0; background: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--ink-2); }
.close:hover { color: var(--ink); }

.form-body, #drawerBody { padding: 1.1rem; overflow-y: auto; }
.form-body { display: grid; gap: .8rem; grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: .73rem; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { resize: vertical; min-height: 68px; font-family: inherit; }
.field.inline { flex-direction: row; align-items: center; gap: .45rem; }
.field.inline label { text-transform: none; letter-spacing: 0; font-size: .82rem; }
.field.inline input { width: auto; }
.fieldset-title {
  grid-column: 1 / -1; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-3); border-top: 1px solid var(--line);
  padding-top: .8rem; margin-top: .2rem;
}
.modal footer {
  display: flex; justify-content: flex-end; gap: .5rem;
  padding: .85rem 1.1rem; border-top: 1px solid var(--line);
}

#drawerBody h4 {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); margin: 1.1rem 0 .5rem;
}
#drawerBody h4:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: .3rem .75rem; font-size: .84rem; }
.kv dt { color: var(--ink-2); }
.kv dd { font-weight: 550; }

/* ---------- Pager & toasts ---------- */

.pager { display: flex; gap: .4rem; align-items: center; justify-content: center; margin-top: 1rem; font-size: .8rem; color: var(--ink-2); }

.toasts { position: fixed; bottom: 1rem; right: 1rem; z-index: 120; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--navy); color: #fff; padding: .6rem .9rem;
  border-radius: 8px; font-size: .84rem; box-shadow: var(--shadow);
  border-left: 3px solid var(--accent); animation: slide .2s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  main { padding: 1rem 16px 3rem; }
  .topbar { gap: .6rem; }
  .tabs { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .form-body { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: .4rem; }
}

/* ---------- Sign-in & account ---------- */

.login-page { min-height: 100vh; display: flex; flex-direction: column; }
.login-wrap {
  flex: 1; display: grid; place-items: center;
  padding: 2rem 1rem; max-width: none; margin: 0;
}
.login-card {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 1rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}
.login-card .brand { margin-bottom: .25rem; }
.login-card .field input { padding: .6rem .7rem; font-size: .95rem; }
.login-error {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line));
  color: var(--danger); border-radius: 7px;
  padding: .55rem .75rem; font-size: .84rem;
}
.login-note { font-size: .74rem; color: var(--ink-3); text-align: center; }
.btn.block { width: 100%; padding: .65rem; font-size: .9rem; }

.user .who { font-weight: 600; color: var(--ink); }
.user .role {
  background: var(--accent); color: #fff; font-weight: 700;
  font-size: .62rem; letter-spacing: .08em; padding: .2rem .45rem; border-radius: 4px;
}
.user form { display: inline; }
