:root {
  --ink: #1f2937;
  --muted: #5b6575;
  --line: #d9e2ec;
  --canvas: #f6f8fb;
  --surface: #ffffff;
  --nav: #242424;
  --blue: #2563eb;
  --green: #059669;
  --amber: #d97706;
  --teal: #0f766e;
  --purple: #714b67;
  --coral: #e11d48;
  --shadow: 0 14px 30px rgba(31, 41, 55, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  min-width: 320px;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

button.good {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

button.danger {
  background: var(--coral);
  border-color: var(--coral);
  color: #fff;
}

button.icon {
  width: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  min-height: 38px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px 1fr;
}

.sidebar {
  background: var(--nav);
  color: #fff;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 0 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,.14);
  margin-bottom: 12px;
}

.brand strong {
  font-size: 20px;
  letter-spacing: 0;
}

.brand span {
  color: rgba(255,255,255,.68);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  border-color: transparent;
  background: transparent;
  color: rgba(255,255,255,.82);
}

.nav button.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.nav .glyph {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255,255,255,.12);
  font-size: 12px;
  flex: 0 0 auto;
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  background: rgba(246,248,251,.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 3;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.content {
  padding: 18px 20px 28px;
  min-width: 0;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, #f7fafc 0%, #edf4f2 100%);
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 26px;
}

.login-panel p {
  margin: 0 0 18px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.toolbar, .subtoolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.subtoolbar {
  align-items: stretch;
}

.search {
  max-width: 360px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  min-height: 86px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 7px;
  font-size: 27px;
}

.board {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 1;
}

td.actions {
  white-space: nowrap;
  width: 1%;
}

.empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 700;
}

.badge.green { color: var(--green); border-color: rgba(5,150,105,.25); background: rgba(5,150,105,.08); }
.badge.amber { color: var(--amber); border-color: rgba(217,119,6,.25); background: rgba(217,119,6,.08); }
.badge.blue { color: var(--blue); border-color: rgba(37,99,235,.25); background: rgba(37,99,235,.08); }
.badge.purple { color: var(--purple); border-color: rgba(113,75,103,.25); background: rgba(113,75,103,.08); }
.badge.red { color: var(--coral); border-color: rgba(225,29,72,.25); background: rgba(225,29,72,.08); }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: 14px;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

.section h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #edf2f7;
}

.kv:last-child {
  border-bottom: 0;
}

.kv span:first-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.42);
  display: grid;
  place-items: start center;
  padding: 5vh 16px;
  overflow: auto;
  z-index: 20;
}

.modal {
  width: min(780px, 100%);
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.modal header, .modal footer {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  padding: 14px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #111827;
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: min(420px, calc(100vw - 36px));
}

.error {
  color: var(--coral);
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.right {
  text-align: right;
}

.mobile-nav {
  display: none;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mobile-nav {
    display: block;
    min-width: 180px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1 1 auto;
  }

  .content {
    padding: 14px;
  }

  .stats, .form-grid {
    grid-template-columns: 1fr;
  }

  .toolbar, .subtoolbar {
    flex-direction: column;
  }

  .search {
    max-width: none;
  }

  .kv {
    grid-template-columns: 1fr;
  }
}
