/* ------------------------------------------------------------------
   KorTrack — KalKortex Systems
   Palette: Kortex Navy #102A4C · Timeless Gold #C9A227 ·
            Signal Slate #6F8299 · Parchment #F5F2EC · Ink #0B1B30
   ------------------------------------------------------------------ */

:root {
  --navy: #102A4C;
  --navy-700: #163864;
  --navy-300: #3C5A83;
  --gold: #C9A227;
  --gold-dark: #B8860B;
  --gold-soft: #F3E6BE;
  --slate: #6F8299;
  --slate-light: #9DABBC;
  --parchment: #F5F2EC;
  --ink: #0B1B30;

  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-2: #FAFAF8;
  --border: #E1E4E9;
  --border-strong: #CBD1DA;

  --text: #16202F;
  --text-2: #5A6779;
  --text-3: #8592A3;

  --chart-todo: #4A76C4;
  --chart-prog: #B8860B;
  --chart-done: #1E9E72;

  --danger: #B5485D;
  --warn: #C07A1E;
  --good: #1E9E72;

  --r: 8px;
  --r-lg: 12px;
  --shadow-1: 0 1px 2px rgba(16, 42, 76, .08), 0 1px 3px rgba(16, 42, 76, .06);
  --shadow-2: 0 4px 12px rgba(16, 42, 76, .10), 0 2px 4px rgba(16, 42, 76, .06);
  --shadow-3: 0 16px 48px rgba(11, 27, 48, .20);
  --sidebar-w: 248px;
  --font: 'Jost', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
#root { height: 100%; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--navy-700); }

/* ---------- primitives ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--slate-light); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-700); border-color: var(--navy-700); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn-gold:hover { background: #D8B03A; border-color: #D8B03A; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(16, 42, 76, .06); border-color: transparent; }
.btn-danger { color: var(--danger); border-color: #E7C9D0; }
.btn-danger:hover { background: #FCF3F5; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

.input, .select, .textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface); outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--navy-300); box-shadow: 0 0 0 3px rgba(60, 90, 131, .14);
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M1 1l4 4 4-4' stroke='%236F8299' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px; }

.label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.muted { color: var(--text-2); }
.tiny { font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- auth ---------- */

.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; background: linear-gradient(160deg, #0D2340 0%, #102A4C 45%, #17395F 100%); }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border-radius: 16px; padding: 34px 32px 30px; box-shadow: var(--shadow-3); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.auth-brand img { width: 40px; height: 40px; }
.auth-brand .wm { font-weight: 700; font-size: 20px; letter-spacing: .02em; color: var(--navy); }
.auth-brand .wm span { font-weight: 500; }
.auth-sub { color: var(--text-2); font-size: 13.5px; margin: 0 0 24px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13.5px; color: var(--text-2); }
.auth-switch button { background: none; border: none; color: var(--navy-700); font-weight: 600; cursor: pointer; padding: 0; }
.notice { padding: 10px 13px; border-radius: var(--r); font-size: 13.5px; margin-bottom: 16px; }
.notice-error { background: #FCF0F2; color: #8E2F42; border: 1px solid #F0D3D9; }
.notice-info { background: #EEF4FB; color: #24466F; border: 1px solid #D6E3F2; }
.notice-ok { background: #EAF7F1; color: #14654A; border: 1px solid #C8E9DA; }

/* ---------- shell ---------- */

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100%; }

.sidebar { background: var(--navy); color: #DCE4EE; display: flex; flex-direction: column; min-height: 0; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 14px; }
.sidebar-brand img { width: 30px; height: 30px; }
.sidebar-brand .wm { font-size: 16.5px; font-weight: 700; letter-spacing: .02em; color: #fff; line-height: 1; }
.sidebar-brand .wm span { font-weight: 500; }
.sidebar-brand .tag { display: block; font-size: 8.5px; letter-spacing: .42em; color: var(--gold); margin-top: 3px; }

.proj-switch { margin: 6px 12px 10px; position: relative; }
.proj-btn { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--r); background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.10); color: #fff; cursor: pointer; text-align: left; }
.proj-btn:hover { background: rgba(255,255,255,.12); }
.proj-key { flex: 0 0 auto; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: var(--gold); color: var(--ink); font-size: 11px; font-weight: 700; }
.proj-name { font-size: 14px; font-weight: 500; }
.proj-menu { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); color: var(--text); border-radius: var(--r); box-shadow: var(--shadow-3); padding: 6px; max-height: 340px; overflow: auto; }
.proj-menu button { width: 100%; display: flex; align-items: center; gap: 9px; padding: 8px 10px; border: none; background: none; border-radius: 6px; cursor: pointer; text-align: left; font-size: 14px; }
.proj-menu button:hover { background: var(--bg); }
.proj-menu .divider { height: 1px; background: var(--border); margin: 6px 4px; }

.nav { padding: 4px 12px; overflow-y: auto; flex: 1; min-height: 0; }
.nav-h { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #7E93AE; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 11px; margin-bottom: 1px;
  border-radius: var(--r); color: #C6D2E1; text-decoration: none; font-size: 14.5px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.on { background: rgba(201, 162, 39, .16); color: #fff; border-left-color: var(--gold); font-weight: 500; }
.nav a svg { flex: 0 0 auto; opacity: .85; }
.nav .count { margin-left: auto; font-size: 12px; color: #8FA2B8; }

.sidebar-foot { border-top: 1px solid rgba(255,255,255,.10); padding: 10px 12px; }
.me-btn { width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--r); background: none; border: none; color: #DCE4EE; cursor: pointer; text-align: left; }
.me-btn:hover { background: rgba(255,255,255,.08); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.topbar h1 { font-size: 19px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.topbar .crumb { font-size: 12.5px; color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; }
.search { position: relative; width: 250px; }
.search input { padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }

.content { flex: 1; min-height: 0; overflow: auto; padding: 20px 22px 40px; }
.content.flush { padding: 0; display: flex; flex-direction: column; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--border); }
.filters .select, .filters .input { width: auto; min-width: 132px; padding: 6px 28px 6px 10px; font-size: 13.5px; }
.filters .input { padding-right: 10px; }

/* ---------- avatars, chips, badges ---------- */

.av { flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 600; font-size: 11px; letter-spacing: .02em; width: 26px; height: 26px; user-select: none; }
.av-sm { width: 22px; height: 22px; font-size: 9.5px; }
.av-lg { width: 34px; height: 34px; font-size: 13px; }
.av-empty { background: var(--surface); border: 1px dashed var(--border-strong); color: var(--text-3); }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }

.type-ic { flex: 0 0 auto; display: grid; place-items: center; width: 17px; height: 17px; border-radius: 4px; font-size: 10px; font-weight: 700; color: #fff; }
.t-epic { background: #7C5CBF; }
.t-story { background: #1E9E72; }
.t-task { background: #4A76C4; }
.t-bug { background: #B5485D; }

.pri { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; }
.pri-highest { color: #A3324A; }
.pri-high { color: #C0562B; }
.pri-medium { color: #9A7B1C; }
.pri-low { color: #4F7A9E; }
.pri-lowest { color: var(--text-3); }

.pts { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); font-size: 11.5px; font-weight: 600; color: var(--text-2); }

.state-pill { padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.state-active { background: #EAF7F1; color: #14654A; }
.state-future { background: #EEF1F5; color: var(--text-2); }
.state-closed { background: #F1EEF7; color: #5B4694; }

/* ---------- board ---------- */

.board { flex: 1; min-height: 0; display: flex; gap: 14px; padding: 18px 22px 24px; overflow-x: auto; align-items: flex-start; }
.col { flex: 0 0 292px; display: flex; flex-direction: column; max-height: 100%; background: #EDEFF3; border-radius: var(--r-lg); border: 1px solid var(--border); }
.col-h { display: flex; align-items: center; gap: 8px; padding: 11px 13px 9px; }
.col-h .nm { font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-2); }
.col-h .n { margin-left: auto; font-size: 12px; color: var(--text-3); background: var(--surface); border-radius: 10px; padding: 1px 8px; }
.col-cat { width: 6px; height: 6px; border-radius: 50%; }
.cat-todo { background: var(--chart-todo); }
.cat-inprogress { background: var(--chart-prog); }
.cat-done { background: var(--chart-done); }
.col-body { flex: 1; min-height: 60px; overflow-y: auto; padding: 0 9px 9px; display: flex; flex-direction: column; gap: 8px; }
.col-body.over { background: rgba(201, 162, 39, .10); border-radius: var(--r); outline: 2px dashed var(--gold); outline-offset: -4px; }
.col-add { margin: 0 9px 9px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 10px 11px; cursor: pointer; box-shadow: var(--shadow-1);
  transition: box-shadow .12s, border-color .12s, transform .12s;
}
.card:hover { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.card.dragging { opacity: .45; transform: rotate(1.2deg); }
.card .ttl { font-size: 14px; line-height: 1.38; margin-bottom: 9px; overflow-wrap: anywhere; }
.card .epic-tag { display: inline-block; max-width: 100%; font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #5B4694; background: #F1EEF7; border-radius: 4px; padding: 1px 6px; margin-bottom: 7px; }
.card-foot { display: flex; align-items: center; gap: 7px; }
.card-foot .ref { font-size: 11.5px; font-weight: 600; color: var(--text-3); letter-spacing: .03em; }
.card-foot .sp { flex: 1; }

/* ---------- backlog ---------- */

.sprint-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 14px; overflow: hidden; }
.sprint-h { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sprint-h .nm { font-weight: 600; font-size: 15px; }
.sprint-h .meta { font-size: 12.5px; color: var(--text-2); }
.sprint-list { min-height: 46px; }
.sprint-list.over { background: rgba(201, 162, 39, .10); outline: 2px dashed var(--gold); outline-offset: -3px; }
.empty-drop { padding: 16px; text-align: center; font-size: 13px; color: var(--text-3); }

.brow { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--border); cursor: pointer; background: var(--surface); }
.brow:last-child { border-bottom: none; }
.brow:hover { background: var(--surface-2); }
.brow.dragging { opacity: .45; }
.brow .ref { font-size: 12px; font-weight: 600; color: var(--text-3); width: 74px; flex: 0 0 auto; letter-spacing: .03em; }
.brow .ttl { flex: 1; min-width: 0; font-size: 14px; }
.brow .st { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 7px; }
.inline-add { display: flex; gap: 8px; padding: 9px 14px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- tables ---------- */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.panel-h { padding: 13px 16px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
table.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl tbody tr.clickable:hover { background: var(--surface-2); }

/* ---------- epics ---------- */

.epic-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 15px 16px; cursor: pointer; transition: box-shadow .12s, border-color .12s; }
.epic-card:hover { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.bar { height: 7px; border-radius: 4px; background: #E6E9EE; overflow: hidden; display: flex; gap: 2px; }
.bar > span { display: block; height: 100%; }

/* ---------- dashboard ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 15px 17px; }
.tile .k { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); font-weight: 700; }
.tile .v { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; line-height: 1.1; }
.tile .s { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.chart-wrap { padding: 8px 16px 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 0 16px 10px; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
svg .axis { stroke: var(--border); stroke-width: 1; }
svg .grid-line { stroke: #EDEFF2; stroke-width: 1; }
svg .tick { font-size: 12px; fill: var(--text-3); }
svg .val { font-size: 12px; fill: var(--text-2); font-weight: 600; }

/* ---------- drawer & modal ---------- */

.scrim { position: fixed; inset: 0; background: rgba(11, 27, 48, .42); z-index: 50; animation: fade .14s ease; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 94vw);
  background: var(--surface); z-index: 51; display: flex; flex-direction: column;
  box-shadow: var(--shadow-3); animation: slide .18s cubic-bezier(.2,.7,.3,1);
}
@keyframes slide { from { transform: translateX(28px); opacity: .4 } to { transform: none; opacity: 1 } }
.drawer-h { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.drawer-b { flex: 1; overflow: auto; padding: 18px 22px 40px; display: grid; grid-template-columns: minmax(0, 1fr) 268px; gap: 24px; align-items: start; }
.drawer-b > * { min-width: 0; }
.side-props { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 14px; position: sticky; top: 0; }
.side-props .field:last-child { margin-bottom: 0; }

.title-edit { font-size: 21px; font-weight: 600; line-height: 1.3; border: 1px solid transparent; border-radius: var(--r); padding: 5px 8px; margin: -5px -8px 14px; width: calc(100% + 16px); background: none; letter-spacing: -.01em; }
.title-edit:hover { background: var(--surface-2); }
.title-edit:focus { background: var(--surface); border-color: var(--navy-300); outline: none; box-shadow: 0 0 0 3px rgba(60,90,131,.14); }

.desc-view { min-height: 62px; padding: 9px 10px; border: 1px solid transparent; border-radius: var(--r); cursor: text; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
.desc-view:hover { background: var(--surface-2); border-color: var(--border); }
.desc-view.placeholder { color: var(--text-3); }

.cmt { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.cmt:last-child { border-bottom: none; }
.cmt .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; margin-top: 3px; }
.act-item { display: flex; gap: 8px; font-size: 12.5px; color: var(--text-2); padding: 5px 0; }

.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: start center; padding: 7vh 16px 16px; overflow: auto; }
.modal { width: 100%; max-width: 620px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-3); animation: pop .15s ease; }
@keyframes pop { from { transform: translateY(-8px); opacity: .5 } to { transform: none; opacity: 1 } }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 16.5px; }
.modal-b { padding: 20px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 9px; background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow-3); animation: pop .15s ease; }
.toast.err { background: #8E2F42; }

.empty { text-align: center; padding: 56px 20px; color: var(--text-2); }
.empty h3 { margin: 12px 0 6px; color: var(--text); font-weight: 600; }
.empty img { width: 52px; height: 52px; opacity: .5; }

.copyfield { display: flex; gap: 8px; }
.copyfield input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .drawer-b { grid-template-columns: 1fr; }
  .side-props { position: static; }
}
