:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #d1d5db;
  --accent: #b45309;
  --accent-dark: #92400e;
  --accent-soft: #fef3c7;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 10px 40px rgba(16, 24, 40, .18);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line-2); color: var(--ink-2);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 550;
  transition: background .12s, border-color .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; border-color: #9ca3af; }
.btn:active { transform: translateY(.5px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--red); border-color: #fecaca; background: #fff5f5; }
.btn.danger:hover { background: #fee2e2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef0f3; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span {
  display: block; font-size: 11.5px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px;
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-2);
  border-radius: 8px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(180,83,9,.12); }
textarea { resize: vertical; min-height: 80px; }
input[type=color] { width: 42px; height: 34px; padding: 2px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* ---------- auth ---------- */
#auth {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(160deg, #1f2937, #374151 55%, #4b5563);
}
.auth-card {
  width: 100%; max-width: 420px; background: #fff; border-radius: 14px;
  padding: 28px; box-shadow: var(--shadow-lg);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.auth-logo .mark { width: 34px; height: 34px; }
.auth-tabs { display: flex; gap: 4px; background: #f3f4f6; padding: 3px; border-radius: 9px; margin: 18px 0 16px; }
.auth-tabs button {
  flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 7px;
  cursor: pointer; font-weight: 600; color: var(--muted);
}
.auth-tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.err { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.okmsg { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; padding: 8px 10px; border-radius: 8px; font-size: 13px; }

/* ---------- shell ---------- */
#app { display: none; min-height: 100vh; }
#app.on { display: grid; grid-template-columns: 224px 1fr; }
aside {
  background: #1f2937; color: #d1d5db; padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
aside .brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 16px; color: #fff; }
aside .brand .name { font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
aside nav { display: flex; flex-direction: column; gap: 2px; }
aside nav a {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px;
  color: #d1d5db; font-weight: 550; cursor: pointer;
}
aside nav a:hover { background: #374151; color: #fff; }
aside nav a.on { background: var(--accent); color: #fff; }
aside .who { border-top: 1px solid #374151; padding-top: 12px; margin-top: 8px; font-size: 12.5px; }
aside .who .nm { color: #fff; font-weight: 600; }

main { min-width: 0; padding: 0 0 60px; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(245,246,248,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding: 14px 24px; display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 19px; }
.content { padding: 20px 24px; }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .hd { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card .hd h3 { font-size: 14px; }
.card .bd { padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.stat .v { font-size: 25px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: #fafafa;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #fafbfc; }
tbody tr.clickable { cursor: pointer; }

/* ---------- pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #f3f4f6; color: var(--ink-2); white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tag { display: inline-block; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-dark); font-size: 11.5px; font-weight: 650; }

/* ---------- board ---------- */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; }
.col { flex: 0 0 248px; background: #eef0f3; border-radius: var(--radius); padding: 10px; min-height: 96px; }
.col.over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.col .ch { display: flex; align-items: center; gap: 7px; padding: 2px 4px 10px; font-weight: 650; font-size: 13px; }
.col .ch .n { background: #fff; border-radius: 999px; padding: 0 7px; font-size: 11.5px; color: var(--muted); }
.jc {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px;
  margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow);
}
.jc:hover { border-color: var(--line-2); }
.jc.dragging { opacity: .45; }
.jc .t { font-weight: 620; margin-bottom: 2px; }
.jc .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,.55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px; overflow: auto;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 720px; box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 980px; }
.modal .mh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .mb { padding: 20px; }
.modal .mf { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: #fafafa; border-radius: 0 0 14px 14px; }
.x { border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.x:hover { background: #f3f4f6; color: var(--ink); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 20px; }
.tabs button {
  border: 0; background: transparent; padding: 11px 12px; cursor: pointer; font-weight: 600;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- notes ---------- */
.note { border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; background: #fff; }
.note.pin { border-color: #fcd34d; background: #fffbeb; }
.note .nh { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.note .body { white-space: pre-wrap; }

/* ---------- files ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(182px, 1fr)); gap: 12px; }
.thumb { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #fff; position: relative; }
.thumb .im { height: 118px; background: #f3f4f6 center/cover no-repeat; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.thumb .cap { padding: 7px 8px; font-size: 12px; }
.thumb .acts { display: flex; gap: 4px; padding: 0 8px 8px; align-items: center; }
.thumb .acts .btn:first-child { flex: 1; justify-content: center; }
.badge-mark { position: absolute; top: 6px; left: 6px; background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 5px; letter-spacing: .03em; }
.drop { border: 2px dashed var(--line-2); border-radius: 10px; padding: 20px; text-align: center; color: var(--muted); background: #fcfcfd; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

/* ---------- annotator ---------- */
#annot { position: fixed; inset: 0; background: #111827; z-index: 300; display: none; flex-direction: column; }
#annot.on { display: flex; }
#annot .bar { background: #1f2937; color: #e5e7eb; padding: 9px 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid #374151; }
#annot .bar .grp { display: flex; gap: 4px; align-items: center; background: #111827; padding: 3px; border-radius: 8px; }
#annot .tool {
  border: 0; background: transparent; color: #d1d5db; padding: 6px 10px; border-radius: 6px;
  cursor: pointer; font-weight: 600; font-size: 12.5px;
}
#annot .tool:hover { background: #374151; color: #fff; }
#annot .tool.on { background: var(--accent); color: #fff; }
#annot .sw { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
#annot .sw.on { border-color: #fff; }
#annot .stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 16px; }
#annot canvas { max-width: 100%; max-height: 100%; background: #000; box-shadow: 0 8px 40px rgba(0,0,0,.6); cursor: crosshair; touch-action: none; }
#annot .foot { background: #1f2937; padding: 10px 14px; display: flex; gap: 10px; align-items: center; border-top: 1px solid #374151; }
#annot .foot input, #annot .foot select { background: #111827; border-color: #374151; color: #e5e7eb; }

/* ---------- toast ---------- */
#toast { position: fixed; right: 18px; bottom: 18px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111827; color: #fff; padding: 10px 14px; border-radius: 9px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 340px; animation: pop .16s ease-out;
}
.toast.bad { background: #b91c1c; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.searchbox { position: relative; flex: 1; max-width: 380px; }
.searchbox input { padding-left: 32px; }
.searchbox svg { position: absolute; left: 9px; top: 9px; opacity: .5; }

.linetable input { padding: 6px 8px; }
.linetable td { padding: 6px; }

@media (max-width: 820px) {
  #app.on { grid-template-columns: 1fr; }
  aside { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  aside .brand { padding: 0 10px 0 0; }
  aside nav { flex-direction: row; }
  aside .who { display: none; }
  .content, .topbar { padding-left: 14px; padding-right: 14px; }
}
