/* ═══════════════════════════════════════════════════════════════════════════
   NID Sync Middleware — Design System
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
  --brand:        #1a56db;
  --brand-dark:   #1242b4;
  --brand-light:  #e8f0fe;
  --sidebar-bg:   #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active-bg: #1e293b;
  --sidebar-active-text: #fff;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --surface-3:    #f1f5f9;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-light:   #94a3b8;
  --success:      #16a34a;
  --success-bg:   #dcfce7;
  --danger:       #dc2626;
  --danger-bg:    #fee2e2;
  --warning:      #d97706;
  --warning-bg:   #fef3c7;
  --info:         #0284c7;
  --info-bg:      #e0f2fe;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow:       0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg:    0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
  --sidebar-w:    240px;
  --header-h:     60px;
  --font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Reset / Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  height: 100%;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1,h2,h3,h4,h5 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.3; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p  { margin: 0 0 .75rem; color: var(--text-muted); }

code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: .85em;
  background: var(--surface-3);
  padding: .1em .35em;
  border-radius: 4px;
  color: var(--brand-dark);
}

/* ── App Shell ─────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 32px; height: 32px;
  background: var(--brand);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex; flex-direction: column;
}

.sidebar-brand-name {
  font-weight: 700;
  font-size: .95rem;
  color: #fff;
  line-height: 1.1;
}

.sidebar-brand-sub {
  font-size: .7rem;
  color: var(--sidebar-text);
  line-height: 1.2;
}

.sidebar-nav {
  flex: 1;
  padding: .75rem 0;
}

.nav-section-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
  padding: .75rem 1.25rem .25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem 1.25rem;
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 500;
  border-radius: 0;
  transition: background .15s, color .15s;
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: rgba(255,255,255,.05);
  color: #fff;
  text-decoration: none;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--brand);
  border-radius: 0 2px 2px 0;
}

.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }

.sidebar-footer {
  padding: .75rem 1.25rem 1rem;
  border-top: 1px solid rgba(255,255,255,.07);
}

.user-info {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .5rem;
}

.user-avatar {
  width: 30px; height: 30px;
  background: var(--brand);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name {
  font-size: .8rem;
  font-weight: 600;
  color: #cbd5e1;
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: #64748b;
  padding: .3rem 0;
  transition: color .15s;
  text-decoration: none;
}

.logout-btn:hover { color: #94a3b8; text-decoration: none; }

/* ── Main Content ──────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.page-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.page-header p {
  font-size: .8rem;
  color: var(--text-muted);
  margin: .15rem 0 0;
}

.page-body {
  padding: 1.75rem 2rem;
  flex: 1;
}

/* ── Flash Messages ────────────────────────────────────────────────────────── */
.flash {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: .875rem;
  font-weight: 500;
}

.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.flash-error   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #fecaca; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-header h3 { margin: 0; font-size: .95rem; }
.card-body  { padding: 1.25rem; }
.card-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── Stat Cards ────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 1.2rem;
}

.stat-icon.blue   { background: var(--brand-light); color: var(--brand); }
.stat-icon.green  { background: var(--success-bg);  color: var(--success); }
.stat-icon.orange { background: var(--warning-bg);  color: var(--warning); }
.stat-icon.purple { background: #f3e8ff; color: #7c3aed; }

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: .2rem;
}

.stat-label {
  font-size: .78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, box-shadow .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--surface-3); color: var(--text); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-sm {
  padding: .35rem .75rem;
  font-size: .8rem;
}

.btn-lg {
  padding: .7rem 1.5rem;
  font-size: .95rem;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2em .6em;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.4;
}

.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .7;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-failed  { background: var(--danger-bg);  color: var(--danger);  }
.badge-running { background: var(--warning-bg); color: var(--warning); animation: pulse-dot 1.5s infinite; }
.badge-running::before { animation: pulse-dot 1.5s infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: .7; }
  50%       { opacity: 1; }
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

table thead {
  background: var(--surface-2);
}

table th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

table tbody tr:last-child td { border-bottom: none; }

table tbody tr:hover { background: var(--surface-2); }

/* ── Progress Bar ──────────────────────────────────────────────────────────── */
.progress-wrap {
  background: var(--surface-3);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin: .5rem 0;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), #6366f1);
  border-radius: 99px;
  transition: width .6s ease;
}

.progress-bar.error { background: var(--danger); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .35rem;
}

.form-control {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  appearance: none;
}

.form-control:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}

.form-control::placeholder { color: var(--text-light); }

select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }

/* ── Sync Panel ────────────────────────────────────────────────────────────── */
.sync-panel {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.sync-panel-text h3 { color: #fff; font-size: 1rem; margin-bottom: .25rem; }
.sync-panel-text p  { color: #94a3b8; margin: 0; font-size: .83rem; }

.sync-status-line {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .75rem;
  font-size: .82rem;
  color: #94a3b8;
}

/* ── Indicators Page ───────────────────────────────────────────────────────── */
.indicators-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.25rem;
  height: calc(100vh - 140px);
}

.section-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-panel-header {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--surface-2);
}

.section-list {
  flex: 1;
  overflow-y: auto;
  padding: .4rem 0;
}

.section-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .55rem 1rem;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: background .12s, border-color .12s;
}

.section-item:hover { background: var(--surface-2); }

.section-item.active {
  background: var(--brand-light);
  border-left-color: var(--brand);
  color: var(--brand-dark);
}

.section-count {
  font-size: .72rem;
  background: var(--surface-3);
  color: var(--text-muted);
  padding: .1em .45em;
  border-radius: 99px;
  font-weight: 600;
  flex-shrink: 0;
}

.section-item.active .section-count {
  background: rgba(26,86,219,.12);
  color: var(--brand);
}

/* ── Indicator List Panel ──────────────────────────────────────────────────── */
.indicator-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.indicator-panel-header {
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--surface);
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box svg {
  position: absolute;
  left: .6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: .5rem .75rem .5rem 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s, background .15s;
}

.search-box input:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}

.indicator-list {
  flex: 1;
  overflow-y: auto;
  padding: .25rem 0;
}

.subsection-group {
  border-bottom: 1px solid var(--border);
}

.subsection-header {
  padding: .55rem 1.25rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.subsection-header:hover { background: var(--surface-3); }

.subsection-toggle { transition: transform .2s; }
.subsection-toggle.collapsed { transform: rotate(-90deg); }

.indicator-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .6rem 1.25rem;
  cursor: pointer;
  transition: background .12s;
  border-left: 3px solid transparent;
}

.indicator-item:hover { background: var(--surface-2); }

.indicator-item.selected {
  background: var(--brand-light);
  border-left-color: var(--brand);
}

.indicator-item input[type="checkbox"] {
  margin-top: .15rem;
  width: 15px; height: 15px;
  accent-color: var(--brand);
  flex-shrink: 0;
  cursor: pointer;
}

.indicator-name-en {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
}

.indicator-name-np {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

.indicator-meta {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-top: .25rem;
}

.tag-inactive {
  font-size: .7rem;
  padding: .1em .45em;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-muted);
  font-weight: 600;
}

/* ── Indicator Footer (selection bar) ─────────────────────────────────────── */
.selection-bar {
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.selection-info {
  font-size: .85rem;
  color: var(--text-muted);
}

.selection-info strong {
  color: var(--brand);
  font-weight: 700;
}

/* ── Login Page ────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  padding: 1.5rem;
}

.login-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.75rem;
}

.login-logo-icon {
  width: 40px; height: 40px;
  background: var(--brand);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1.2rem;
}

.login-logo-text h2 { font-size: 1.1rem; margin: 0; }
.login-logo-text p  { font-size: .78rem; color: var(--text-muted); margin: .1rem 0 0; }

/* ── Schedule Page ─────────────────────────────────────────────────────────── */
.schedule-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.time-selector {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.time-separator {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: 1rem 0 0;
}

.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius);
  font-size: .83rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}

.page-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.page-btn.disabled { opacity: .4; pointer-events: none; }

/* ── Toggle / Checkbox ─────────────────────────────────────────────────────── */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.toggle {
  position: relative;
  width: 40px; height: 22px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: background .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

.toggle-label { font-size: .875rem; font-weight: 500; color: var(--text); }

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8rem; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .indicators-layout { grid-template-columns: 1fr; height: auto; }
  .section-panel { max-height: 220px; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .page-body { padding: 1rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .schedule-grid { grid-template-columns: 1fr; }
}
