:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #eef0f3;
  --text: #1c2029;
  --text-mid: #5c6474;
  --text-dim: #8992a3;
  --primary: #1e2a5f;
  --primary-hover: #111a3e;
  --accent: #3a6df0;
  --active-bg: #eef2ff;
  --success-bg: #e8f9f0;
  --success-text: #1cb87e;
  --danger-text: #d93025;
  --radius-sm: 10px;
  --radius-md: 10px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(20,20,43,0.04), 0 8px 24px -12px rgba(20,20,43,0.06);
}

body.dark {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #c9d1d9;
  --text-mid: #8b949e;
  --text-dim: #6e7681;
  --primary: #58a6ff;
  --primary-hover: #79c0ff;
  --accent: #58a6ff;
  --active-bg: #1c2b4a;
  --danger-text: #ff7b72;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.4);
}

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

html {
  color-scheme: light dark;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.material-symbols-outlined {
  font-variation-settings:
    'FILL' 0,
    'wght' 400,
    'GRAD' 0,
    'opsz' 24;
}

/* ===== Layout ===== */
.app {
  display: grid;
  grid-template-columns: 15rem 1fr;
  min-height: 100vh;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.content {
  padding: 1.25rem 1.75rem 2rem;
  max-width: 90rem;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  border-bottom: 1px solid var(--border);
}

.brand img {
  max-width: 100%;
  max-height: 36px;
  width: auto;
  height: auto;
}

.logo-light { display: block; }
.logo-dark { display: none; }

body.dark .logo-light { display: none; }
body.dark .logo-dark { display: block; }

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-mid);
  font-weight: 500;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}

.nav-item .left {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.nav-item svg {
  width: 1.125rem;
  height: 1.125rem;
  stroke-width: 2;
}

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

.nav-item.active {
  background: var(--active-bg);
  color: var(--accent);
  font-weight: 600;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.75rem;
  min-height: 60px;
  box-sizing: border-box;
}

.top-search {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.5rem 1rem;
  width: 18rem;
  max-height: 44px !important;
  height: 44px;
  box-sizing: border-box;
  color: var(--text-dim);
}

.top-search input {
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  color: var(--text);
  width: 100%;
  margin: 0;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mid);
}

.icon-btn .material-symbols-outlined {
  font-size: 1.25rem;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.icon-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

.icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.btn,
.btn--lg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
}

.btn--lg {
  height: 38px;
  min-width: 110px;
  font-size: 14px;
  padding: 0 20px;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

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

/* ===== Content ===== */
h2 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.25rem;
  font-weight: 700;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

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

th, td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

button, .btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}

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

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}

input[type="checkbox"] {
  width: auto;
  margin-right: 0.5rem;
}

.error {
  color: #cf222e;
}

.output {
  margin-top: 1rem;
  padding: 1rem;
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ===== Table cards ===== */
.table-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.table-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.tc-title {
  font-size: 0.6875rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}

.tc-name {
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  margin-bottom: 0.75rem;
}

.tc-metric {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.tc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.tc-percent {
  font-weight: 600;
  color: var(--success-text);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.tc-percent.empty,
.tc-percent.empty .tc-battery {
  color: var(--text-dim);
}

.tc-percent.low,
.tc-percent.low .tc-battery {
  color: var(--danger-text);
}

.tc-percent.mid,
.tc-percent.mid .tc-battery {
  color: #f59e0b;
}

.tc-percent.high,
.tc-percent.high .tc-battery {
  color: var(--success-text);
}

.tc-battery {
  font-size: 1.25rem;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.tc-progress {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}

.tc-progress-fill {
  height: 100%;
  background: var(--success-text);
  border-radius: 2px;
  transition: width 0.3s ease;
}

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

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 48rem;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
}

.modal h3 {
  margin: 0 0 0.75rem;
  font-size: 1.125rem;
}

.modal-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.modal-status {
  color: var(--text-dim);
  font-size: 0.875rem;
}

.modal-percent {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  z-index: 2;
}

.progress-bar {
  height: 1.25rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 1rem;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: var(--success-text);
  border-radius: var(--radius-sm);
  transition: width 0.3s ease;
}

.modal-log {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.75rem;
  line-height: 1.5;
  margin: 0 0 1rem;
  white-space: pre-wrap;
  color: var(--text-mid);
  max-height: 16rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

/* ===== Utilities ===== */
.hidden {
  display: none;
}

.notif-panel.hidden,
.notif-count.hidden {
  display: none;
}

/* ===== Notifications ===== */
.top-right {
  position: relative;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.icon-btn--ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.icon-btn--ghost:hover {
  background: var(--bg);
}

.notif-toggle {
  position: relative;
}

.notif-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger-text);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.overall-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.15rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
}

.status-low {
  color: var(--danger-text);
}

.status-mid {
  color: #f59e0b;
}

.status-high {
  color: var(--success-text);
}

.notif-panel {
  position: absolute;
  top: 5px;
  right: 0;
  width: 22rem;
  max-width: calc(100vw - 2rem);
  height: 96vh;
  max-height: 96vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.notif-panel-title {
  font-weight: 600;
  font-size: 0.9375rem;
}

.notif-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.notif-panel-actions .mark-read,
.notif-page-header .mark-read {
  color: var(--success-text);
}

.notif-panel-actions .expand {
  color: var(--accent);
}

.notif-panel-actions .close {
  color: var(--danger-text);
}

.notif-list,
.notif-page-list {
  overflow: auto;
  padding: 0.5rem 0;
}

.notif-list {
  flex: 1;
  max-height: none;
}

.notif-panel-actions .icon-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
}

.notif-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.875rem;
}

.notif-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.notif-item:last-child {
  border-bottom: none;
}

.notif-item.unread {
  background: var(--active-bg);
}

.notif-item-message {
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--text);
}

.notif-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.notif-item-time {
  font-size: 0.6875rem;
  color: var(--text-dim);
}

.notif-item-read {
  color: var(--success-text);
  width: 1.75rem;
  height: 1.75rem;
}

/* Notifications page */
.notif-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.notif-page-header h3 {
  margin: 0;
  font-size: 1rem;
}

/* ===== History ===== */
.history-table {
  width: 100%;
  border-collapse: collapse;
}

.history-table th,
.history-table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.history-table th {
  color: var(--text-dim);
  font-weight: 500;
}

.run-id {
  word-break: break-all;
  max-width: 12rem;
  font-family: monospace;
  font-size: 0.8125rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.detail-grid > div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
}

.detail-grid strong {
  display: block;
  color: var(--text-dim);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.detail-section {
  margin-bottom: 1rem;
}

.detail-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
}

.detail-tables {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.75rem;
  line-height: 1.4;
  max-height: 8rem;
  overflow: auto;
}

/* ===== Responsive ===== */
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 1rem; }
  .top-search { width: 100%; max-width: 14rem; }
  .table-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 500px) {
  .table-grid { grid-template-columns: 1fr; }
}
