/* ===== VARIABLES ===== */
:root {
  --bg: #f0f4f8;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --soft: #f1f5f9;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #2563eb;
  --shadow: 0 1px 3px rgba(15,23,42,.07), 0 6px 20px rgba(15,23,42,.05);
  --shadow-lg: 0 8px 32px rgba(15,23,42,.12);
  --radius: 12px;
  --radius-sm: 8px;
  --topbar: #ffffff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --soft: #263044;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-soft: #1e3a5f;
  --success: #22c55e;
  --success-soft: #052e16;
  --warning: #f59e0b;
  --warning-soft: #2d1a00;
  --danger: #f87171;
  --danger-soft: #3b0a0a;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
  --topbar: #1e293b;
  color-scheme: dark;
}

/* ===== RESET ===== */
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); transition: background .2s, color .2s; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 18px; line-height: 1.2; }
h2 { font-size: 26px; line-height: 1.15; font-weight: 800; }
h3 { font-size: 15px; line-height: 1.25; font-weight: 700; }
p { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ===== AUTH ===== */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 60% 0%, rgba(37,99,235,.12) 0%, transparent 60%),
              radial-gradient(ellipse at 0% 100%, rgba(22,163,74,.08) 0%, transparent 50%),
              var(--bg);
}
.auth-card {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.logo-img { width: 64px; height: 64px; flex: 0 0 64px; display: flex; align-items: center; justify-content: center; }
.logo-img img { width: 100%; height: 100%; object-fit: contain; border-radius: 8px; }
/* sidebar logo */
.sidebar-brand { padding: 28px 24px 20px; display: flex; justify-content: center; align-items: center; border-bottom: 1px solid var(--line); }
.sidebar-brand img { width: 180px; height: 180px; object-fit: contain; border-radius: 14px; display: block; }

.tabs {
  display: grid; grid-template-columns: repeat(2, 1fr);
  margin-bottom: 20px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--soft);
}
.tab {
  min-height: 38px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; font-weight: 700; transition: all .15s;
}
.tab + .tab { border-left: 1px solid var(--line); }
.tab.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.auth-form, .form-grid { display: grid; gap: 14px; }

/* ===== FORM ELEMENTS ===== */
label { display: grid; gap: 6px; color: var(--text); font-size: 13px; font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 42px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 12px; outline: none;
  background: var(--panel); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input[type="file"] { padding: 8px 12px; min-height: 40px; cursor: pointer; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
input[readonly] { background: var(--soft); color: var(--muted); cursor: default; }

/* ===== BUTTONS ===== */
.btn {
  min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 14px; background: var(--panel); color: var(--text);
  font-size: 13px; font-weight: 700; white-space: nowrap;
  transition: all .15s; cursor: pointer;
}
.btn:hover { background: var(--soft); }
.btn.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.good { border-color: #bbf7d0; background: var(--success-soft); color: var(--success); }
.btn.good:hover { background: #dcfce7; }
.btn.bad { border-color: #fecaca; background: var(--danger-soft); color: var(--danger); }
.btn.bad:hover { background: #fee2e2; }
.btn.full { width: 100%; margin-top: 4px; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 12px; }

/* ===== STATUS ===== */
.error { color: var(--danger); font-size: 13px; font-weight: 700; padding: 10px 14px; border: 1px solid #fecaca; border-radius: var(--radius-sm); background: var(--danger-soft); }
.message { color: var(--success); font-size: 13px; font-weight: 700; padding: 10px 14px; border: 1px solid #bbf7d0; border-radius: var(--radius-sm); background: var(--success-soft); }

/* ===== TOPBAR ===== */
.topbar { border-bottom: 1px solid var(--line); background: var(--topbar); box-shadow: var(--shadow); position: sticky; top: 0; z-index: 100; }
.topbar-inner { min-height: 56px; padding: 0 24px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.theme-toggle {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--line); border-radius: 50%;
  background: var(--panel); color: var(--muted);
  font-size: 16px; cursor: pointer; transition: all .15s; padding: 0;
}
.theme-toggle:hover { background: var(--soft); color: var(--text); border-color: var(--primary); }

/* ===== LAYOUT ===== */
.sidebar {
  position: fixed; left: 0; top: 0; width: 250px; height: 100vh;
  overflow-y: auto; overflow-x: hidden;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 200;
  padding-bottom: 16px;
}
.nav-spacer { flex: 1; min-height: 16px; }
.main-area { margin-left: 250px; min-height: 100vh; display: flex; flex-direction: column; }

/* ===== SIDEBAR NAV ===== */
.nav-group { display: grid; gap: 2px; padding: 4px 8px; }
.nav-title { padding: 8px 8px 3px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.nav-btn {
  min-height: 38px; display: flex; align-items: center; gap: 8px;
  border-radius: var(--radius-sm); padding: 0 12px;
  color: var(--muted); font-size: 13px; font-weight: 600; transition: all .15s;
}
.nav-btn:hover { background: var(--soft); color: var(--text); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }

/* ===== CONTENT ===== */
.content { display: grid; gap: 16px; min-width: 0; padding: 24px; }
.page-title { display: grid; gap: 4px; padding-bottom: 8px; }

/* ===== PANELS ===== */
.panel {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow); padding: 24px; overflow: hidden;
}
.form-panel { max-width: 880px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}

/* ===== METRICS ===== */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow); padding: 16px;
  transition: box-shadow .15s;
}
.metric:hover { box-shadow: var(--shadow-lg); }
.metric span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.metric strong { display: block; margin-top: 8px; font-size: 28px; line-height: 1; font-weight: 800; }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: 13px; background: var(--panel); }
thead th { background: var(--soft); border-top: 0; }
th, td { padding: 11px 12px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover td { background: var(--soft); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap;
}
.badge.ok { background: #dcfce7; color: var(--success); }
.badge.wait { background: #fef3c7; color: var(--warning); }
.badge.bad { background: #fee2e2; color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

/* ===== MISC ===== */
.inline { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
/* ===== BUTTON GROUP ===== */
.btn-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-group form { display: contents; }

.hidden { display: none !important; }
.empty {
  padding: 20px; border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm); color: var(--muted);
  background: var(--soft); font-size: 13px; font-weight: 600; text-align: center;
}

/* ===== SORTING ===== */
th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-sort]:hover { color: var(--text); background: var(--line); }
.sort-icon { font-style: normal; margin-left: 4px; opacity: .35; font-size: 10px; }
th[data-sort][data-dir="asc"] .sort-icon,
th[data-sort][data-dir="desc"] .sort-icon { opacity: 1; color: var(--primary); }

/* ===== TABLE ACTIONS ===== */
.action-row { display: flex; flex-direction: column; gap: 6px; min-width: 210px; }
.upload-row { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.upload-file-input {
  flex: 1; min-width: 0; font-size: 11px;
  padding: 4px 8px; min-height: 30px;
  border: 1.5px solid var(--line); border-radius: 6px;
  background: var(--soft); cursor: pointer;
}
.upload-file-input:focus { border-color: var(--primary); outline: none; }
.table-action { margin-top: 14px; }

/* ===== ANNOUNCEMENT POPUP ===== */
.ann-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.55); backdrop-filter: blur(2px);
  z-index: 999; align-items: center; justify-content: center; padding: 20px;
}
.ann-overlay.show { display: flex; }
.ann-modal {
  width: min(100%, 480px); background: var(--panel);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 28px 28px 24px; position: relative;
  animation: ann-in .25s ease;
  border-top: 4px solid var(--primary);
}
@keyframes ann-in { from { transform: translateY(-16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.ann-modal h3 { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.ann-modal p { font-size: 14px; line-height: 1.7; color: var(--text); }
.ann-close {
  position: absolute; top: 14px; right: 14px;
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  border: none; background: var(--soft); border-radius: 50%;
  color: var(--muted); font-size: 14px; cursor: pointer; transition: all .15s;
}
.ann-close:hover { background: var(--danger); color: #fff; }
.ann-footer { margin-top: 20px; display: flex; justify-content: flex-end; }

/* ===== TC FILTER ===== */
.tc-filter-wrap { margin-bottom: 10px; }
.tc-filter-wrap input { max-width: 260px; min-height: 36px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .sidebar { width: 200px; }
  .main-area { margin-left: 200px; }
  .sidebar-brand img { width: 140px; height: 140px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .sidebar { width: 0; overflow: hidden; }
  .main-area { margin-left: 0; }
  .auth-card { padding: 22px; }
  .metrics, .inline, .upload-row { grid-template-columns: 1fr; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  h2 { font-size: 22px; }
  .content { padding: 16px; }
}
