:root {
  --bg: #0f1115;
  --panel: #181b21;
  --panel-2: #1f232b;
  --border: #23262e;
  --text: #e6e6e6;
  --text-muted: #9aa0a6;
  --hover: #1c2028;
  --accent: #f4652e;
  --accent-hover: #e0551e;
  --danger: #d64545;
  --danger-hover: #bd3a3a;
  --shadow: 0 10px 30px rgba(0,0,0,.4);
}
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --border: #e2e4e9;
  --text: #1a1c20;
  --text-muted: #6b7280;
  --hover: #f7f8fa;
  --shadow: 0 10px 30px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, Segoe UI, Roboto, sans-serif;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { height: 34px; width: auto; display: block; }
.brand-title { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title .company { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
header h1 { font-size: 16px; margin: 0; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}
.theme-toggle:hover { background: var(--hover); }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  padding: 12px 16px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.global-filters { margin-bottom: 24px; }

.sync-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  margin: -12px 0 24px;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--hover); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.filters {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.filters input,
.filters select {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 24px; font-weight: 700; }

.stats-note {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
}
.chart-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}
.chart-box h3 { margin: 0 0 12px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
}

.table-scroll { overflow-x: auto; border-radius: 10px; }
.table-scroll table { min-width: 1100px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
thead th { text-align: left; padding: 10px 12px; background: var(--panel-2); font-size: 12px; color: var(--text-muted); text-transform: uppercase; }
tbody td { padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13px; }
tbody tr:hover { background: var(--hover); }
.loading { text-align: center; color: var(--text-muted); padding: 24px; }

.col-check { width: 36px; }
thead th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
thead th.sortable:hover { color: var(--text); }
thead th.sortable .sort-arrow { display: inline-block; margin-left: 4px; opacity: .5; font-size: 10px; }
thead th.sortable.sort-active .sort-arrow { opacity: 1; color: var(--accent); }

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

.status-badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.status-open { background: #2e4a6b; color: #9cc3ef; }
.status-closed { background: #2e6b3e; color: #9cefa8; }
.status-draft { background: #4a4a4a; color: #ccc; }
.status-void { background: #6b2e2e; color: #efb2b2; }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 16px; }
.pager span { font-size: 13px; color: var(--text-muted); }

.failures { margin-top: 40px; }
.failures h2 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--danger); color: white; border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.failure-item { background: var(--panel); border-left: 3px solid var(--danger); padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; font-size: 13px; }
.failure-item .reason { font-weight: 600; color: #ffb0b0; }
:root[data-theme="light"] .failure-item .reason { color: #b23a3a; }

.sent-ok { color: #2e9e4a; font-size: 12px; }
:root:not([data-theme="light"]) .sent-ok { color: #9cefa8; }
.sent-error { color: #d64545; font-size: 12px; }
:root:not([data-theme="light"]) .sent-error { color: #ff9b9b; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-box { background: var(--panel); padding: 24px; border-radius: 12px; width: 380px; box-shadow: var(--shadow); }
.modal-box h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.modal-box-wide { width: min(700px, 92vw); max-height: 85vh; overflow-y: auto; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 20px;
  margin-bottom: 18px;
  font-size: 13px;
}
.detail-label { display: block; font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.detail-items-table { width: 100%; }
.detail-items-table th, .detail-items-table td { font-size: 12px; }

/* Login page */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel); padding: 32px; border-radius: 12px; width: 320px; box-shadow: var(--shadow); position: relative; }
.login-box .theme-toggle { position: absolute; top: 16px; right: 16px; }
.login-logo { display: block; height: 64px; width: auto; margin: 0 auto 24px; }
.login-box h1 { font-size: 15px; margin: 0 0 20px; text-align: center; color: var(--text-muted); font-weight: 500; }
.login-box label { display: block; font-size: 13px; color: var(--text-muted); margin: 14px 0 6px; }
.login-box input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px;
}
.login-box .btn { width: 100%; margin-top: 20px; }
.login-box .error { color: #ff6b6b; font-size: 13px; margin-top: 12px; min-height: 16px; }
