:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232733;
  --border: #2e3344;
  --text: #e1e4ed;
  --text-muted: #8b90a0;
  --primary: #4f8ff7;
  --primary-hover: #3a7de6;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', monospace;
}

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

[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Login */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
  width: 380px;
  text-align: center;
}

.login-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 14px;
}

.login-card input {
  display: block;
  width: 100%;
  margin-bottom: 12px;
}

.login-card button {
  width: 100%;
  margin-top: 8px;
}

.error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* Inputs */
input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

textarea { resize: vertical; }

button {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}

button:hover { background: var(--border); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 13px;
}

.btn-link:hover { color: var(--text); }

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  line-height: 1;
  padding: 0 4px;
}

.btn-danger { color: var(--danger); }

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 32px;
}

.header-left h1 { font-size: 18px; font-weight: 700; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

nav { display: flex; gap: 4px; }

.tab {
  background: none;
  border: none;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active { color: var(--primary); background: var(--surface2); }

/* Main */
main { padding: 24px; max-width: 1200px; margin: 0 auto; }

.view h2 { font-size: 18px; margin-bottom: 16px; }

.dashboard-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.dashboard-title-row h2 { margin-bottom: 0; }

.date-filter {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.date-filter input { padding: 5px 8px; font-size: 12px; }
.date-preset.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Search */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-input { flex: 1; }

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filters input { flex: 1; min-width: 140px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-muted);
  gap: 12px;
}

.toolbar > div { display: flex; align-items: center; gap: 8px; }
.toolbar input { width: 200px; }

/* Suggest Card */
.suggest-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.suggest-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.suggest-result {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.suggest-name {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--success);
}

.suggest-meta {
  font-size: 12px;
  color: var(--text-muted);
}

#avail-result {
  font-weight: 600;
  font-size: 13px;
}

/* Tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tr:hover td { background: var(--surface2); }

td.sig-name-cell {
  color: var(--primary);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
}

td.sig-name-cell:hover { text-decoration: underline; }

.btn-history {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}
.btn-history:hover { background: var(--border); }

.action-ADD { color: var(--success); }
.action-EDIT { color: var(--warning); }
.action-REM { color: var(--danger); }

/* Forms */
.entry-form { max-width: 720px; }

.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  align-items: flex-end;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  flex: 1;
}

.form-row label.full { flex: 100%; }

.form-row label input,
.form-row label select,
.form-row label textarea { width: 100%; }

.hint { font-weight: 400; font-size: 12px; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

#create-msg { font-size: 13px; }
.msg-ok { color: var(--success); }
.msg-err { color: var(--danger); }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-card .label { font-size: 12px; color: var(--text-muted); }
.stat-card .value { font-size: 28px; font-weight: 700; }

/* Dashboard */
.dashboard-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.dashboard-section h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.dashboard-row {
  display: flex;
  gap: 16px;
}

.dashboard-section.half { flex: 1; }

.chart-container { min-height: 40px; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.bar-label {
  min-width: 100px;
  text-align: right;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 20px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  min-width: 2px;
}

.bar-value {
  min-width: 40px;
  font-size: 12px;
  color: var(--text-muted);
}

.inline-bar {
  display: inline-block;
  height: 14px;
  background: var(--primary);
  border-radius: 2px;
  vertical-align: middle;
}

.monthly-chart {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 250px;
  padding-top: 8px;
  overflow-x: auto;
}

.monthly-bar-group {
  min-width: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.monthly-stack {
  width: 100%;
  display: flex;
  flex-direction: column-reverse;
}

.monthly-stack div {
  width: 100%;
  min-height: 0;
}

.monthly-label {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 4px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  height: 55px;
  white-space: nowrap;
}

.analyst-trend {
  display: grid;
  gap: 8px;
  min-width: 620px;
}

.analyst-trend-header,
.analyst-trend-row {
  display: grid;
  grid-template-columns: 90px repeat(12, minmax(32px, 1fr));
  align-items: end;
  gap: 4px;
}

.analyst-trend-header {
  color: var(--text-muted);
  font-size: 11px;
  padding-bottom: 4px;
}

.analyst-trend-row > strong {
  align-self: center;
  font-size: 12px;
}

.analyst-cell {
  display: flex;
  align-items: end;
  justify-content: center;
  height: 38px;
  border-bottom: 1px solid var(--border);
}

.analyst-cell i {
  display: block;
  width: 75%;
  min-height: 0;
  border-radius: 2px 2px 0 0;
}

.empty-state { color: var(--text-muted); font-size: 13px; }

@media (max-width: 760px) {
  .dashboard-title-row { align-items: flex-start; flex-direction: column; }
  .date-filter { justify-content: flex-start; }
  .dashboard-row { flex-direction: column; }
}

/* Keys */
.banner {
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}

.banner code {
  display: block;
  margin-top: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  user-select: all;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h2 { font-size: 16px; }

/* Detail */
.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  font-size: 13px;
}

.detail-grid dt {
  color: var(--text-muted);
  font-weight: 600;
}

.detail-grid dd {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
