:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --stroke: #e5e7eb;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #1d5df2;
  --primary-2: #0d13ba;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --orange: #f97316;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* Header Styles */
.topbar.flat {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-dot {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 18px;
  box-shadow: var(--shadow);
}

.brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.2px;
  color: var(--text);
}

/* Navigation Styles */
.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tabs a {
  position: relative;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
}

.tabs a:hover {
  background: var(--panel-2);
  color: var(--primary);
}

.tabs a.active {
  color: var(--primary);
  font-weight: 600;
}

.tabs a.active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 4px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
}

.tabs a.logout {
  color: var(--red);
  margin-left: 4px;
}

.tabs a.logout:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Container & Layout */
.container.flat {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Card Styles */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: all 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card h3 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* Form Elements */
.input, textarea, select {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  transition: all 0.2s ease;
}

.input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.searchbar {
  display: flex;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
}

/* Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 14px;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.btn:hover {
  background: var(--primary-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn:active {
  transform: translateY(0);
}

.btn.secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
}

.btn.secondary:hover {
  background: var(--panel-2);
  border-color: var(--primary);
  color: var(--primary);
}

.btn.danger {
  background: #fee2e2;
  color: var(--red);
}

.btn.danger:hover {
  background: #fecaca;
}

.btn.small {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

/* Table Styles */
.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.grid thead th {
  background: var(--panel-2);
  border-bottom: 1px solid var(--stroke);
  padding: 14px 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.grid tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--stroke);
  color: var(--text);
}

.grid tbody tr:last-child td {
  border-bottom: none;
}

.grid tbody tr:hover {
  background: var(--panel-2);
}

/* Badge & Pill Styles */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--stroke);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef2ff;
  border: 1px solid var(--stroke);
  color: #4338ca;
  font-size: 12px;
  font-weight: 600;
}

.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  background: #eef6ff;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
}

/* Level Indicators */
.level-tag {
  font-weight: 700;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
}

.level-high {
  background: #dcfce7;
  color: #166534;
}

.level-mid {
  background: #dbeafe;
  color: #1d4ed8;
}

.level-low {
  background: #fff7ed;
  color: #c2410c;
}

.level-zero {
  background: #fef2f2;
  color: #b91c1c;
}

.levelbar {
  display: inline-block;
  vertical-align: middle;
  width: 80px;
  height: 6px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  margin-left: 8px;
}

.levelbar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #60a5fa, #22c55e);
  width: 40%;
  border-radius: 999px;
}

.levelbar.high i {
  width: 100%;
  background: var(--green);
}

.levelbar.mid i {
  width: 60%;
  background: #3b82f6;
}

.levelbar.low i {
  width: 30%;
  background: var(--yellow);
}

.levelbar.zero i {
  width: 10%;
  background: var(--red);
}

/* Scrollable Cell */
.scrollcell {
  max-width: 520px;
  overflow-x: auto;
  white-space: nowrap;
  background: var(--panel-2);
  border-radius: 8px;
  border: 1px solid var(--stroke);
  padding: 8px 12px;
  font-family: 'Courier New', monospace;
  font-size: 14px;
}

.scrollcell::-webkit-scrollbar {
  height: 6px;
}

.scrollcell::-webkit-scrollbar-thumb {
  background: #c7d2fe;
  border-radius: 999px;
}

/* Notice Styles */
.notice {
  padding: 14px 16px;
  border-radius: var(--radius);
  margin: 16px 0;
  border: 1px solid var(--stroke);
  font-weight: 500;
  display: flex;
  align-items: center;
}

.notice.ok {
  background: #f0fdf4;
  color: #065f46;
  border-color: #bbf7d0;
}

.notice.err {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

/* Footer */
.footer {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  border-top: 1px solid var(--stroke);
  margin-top: 24px;
  font-size: 14px;
}

/* Layout Helpers */
.row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.col {
  flex: 1;
  min-width: 280px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .topbar.flat {
    padding: 12px 16px;
  }
  
  .container.flat {
    padding: 16px;
  }
  
  .cards {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .searchbar {
    flex-direction: column;
  }
  
  .grid {
    font-size: 14px;
  }
  
  .grid thead th,
  .grid tbody td {
    padding: 12px 10px;
  }
  
  .scrollcell {
    max-width: 300px;
  }
  
  .row {
    flex-direction: column;
    gap: 12px;
  }
  
  .col {
    min-width: 100%;
  }
}

@media (max-width: 480px) {
  .tabs {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .tabs a {
    padding: 8px 12px;
    font-size: 13px;
  }
  
  .tabs a.active::after {
    left: 12px;
    right: 12px;
  }
  
  .btn {
    padding: 8px 14px;
    font-size: 13px;
  }
}