:root {
  --bg: #e8edf2;
  --panel: #ffffff;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --line: #c5d0db;
  --header: #1f4e79;
  --accent: #0b6e4f;
  --accent-hover: #095c42;
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
  --row-alt: #f5f8fb;
  --font: "Segoe UI", "Be Vietnam Pro", Tahoma, sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 13px;
}

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; height: 48px;
  background: #12324f; color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 15px; }
.agent-pill {
  margin-left: auto; margin-right: 8px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.12); font-size: 12px; font-weight: 600;
}
.agent-pill.on { background: #067647; }
.agent-pill.off { background: #b42318; }

.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; color: #c9d7e6;
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font: inherit;
}
.tab:hover { background: rgba(255,255,255,0.08); color: #fff; }
.tab.active { background: #fff; color: #12324f; font-weight: 600; }

main { padding: 12px 0 24px; }
.panel { display: none; padding: 0 12px; }
.panel.active { display: block; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px; flex-wrap: wrap;
}
.toolbar h1, .sync-box h2, .sync-history h2 {
  margin: 0 0 8px; font-size: 16px; font-weight: 700;
}
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 6px; cursor: pointer;
  font: inherit; font-weight: 600;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.health-bar {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 10px;
  color: var(--muted); font-weight: 600;
}
.health-bar strong { color: var(--ink); }

.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px; margin-bottom: 14px;
}
.device-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px;
}
.device-card .name { font-weight: 700; font-size: 14px; }
.device-card .meta { color: var(--muted); margin: 4px 0 10px; font-family: var(--mono); font-size: 12px; }
.device-card .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.status-line { margin-top: 8px; min-height: 18px; color: var(--muted); }
.device-card .time-box {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: grid;
  gap: 6px;
}
.device-card .time-box input[type="datetime-local"] {
  height: 32px;
  width: 100%;
}
.device-card .time-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.badge.on { background: #dcfae6; color: var(--ok); }
.badge.off { background: #fee4e2; color: var(--danger); }

.sync-box, .sync-history {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px; margin-bottom: 12px;
}
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr auto;
  gap: 10px; align-items: end;
}
label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
input, select {
  height: 34px; border: 1px solid var(--line); border-radius: 6px;
  padding: 0 10px; font: inherit; color: var(--ink); background: #fff;
}
.log {
  margin: 10px 0 0; background: #0f1b28; color: #d7e6f5;
  padding: 10px 12px; border-radius: 6px; min-height: 72px; max-height: 240px;
  overflow: auto; font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
}

.filters {
  display: grid; grid-template-columns: 1.6fr 1fr 0.9fr 0.9fr auto;
  gap: 10px; align-items: end; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 10px;
}
.filters .grow { min-width: 0; }
.summary { margin-bottom: 8px; color: var(--muted); font-weight: 600; }
.summary strong { color: var(--ink); }

.excel-wrap {
  width: 100%; overflow: auto; border: 1px solid #8fa3b8;
  background: #fff; max-height: calc(100vh - 220px);
}
.excel {
  border-collapse: collapse; min-width: 1100px; width: 100%;
  table-layout: fixed; font-size: 12px;
}
.excel th, .excel td {
  border: 1px solid #9eb1c4; padding: 4px 6px;
  vertical-align: middle; white-space: nowrap;
}
.excel thead th {
  background: var(--header); color: #fff; font-weight: 600;
  text-align: center; position: sticky; top: 0; z-index: 5;
}
.excel tbody tr:nth-child(even) { background: var(--row-alt); }
.excel tbody tr:hover { background: #e8f2ff; }
.excel .empty { text-align: center; color: var(--muted); padding: 28px; }
.excel .center { text-align: center; }
.excel .sticky { position: sticky; left: 0; z-index: 6; background: var(--header); }
.hint { color: var(--muted); margin: 8px 2px 0; font-size: 12px; }

.table-scroll { overflow: auto; }
table.plain { border-collapse: collapse; width: 100%; min-width: 720px; }
table.plain th, table.plain td {
  border: 1px solid var(--line); padding: 6px 8px; text-align: left;
}
table.plain th { background: #eef3f8; }
.ok { color: var(--ok); font-weight: 700; }
.err { color: var(--danger); font-weight: 700; }

@media (max-width: 900px) {
  .form-grid, .filters { grid-template-columns: 1fr 1fr; }
  .form-actions, .filters .btn { grid-column: 1 / -1; }
  .agent-pill { display: none; }
}
