:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef2f7;
  --text: #111827;
  --muted: #667085;
  --border: #d9dee8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --good: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--border);
  background: #fbfcfe;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--text);
  color: white;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.nav-item:hover {
  background: var(--surface-soft);
}

.nav-item.active {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: var(--primary-dark);
  font-weight: 700;
}

.content {
  width: min(1180px, 100%);
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: 30px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 150px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.score-pill span {
  color: var(--muted);
  font-size: 13px;
}

.score-pill strong {
  margin-left: auto;
  font-size: 26px;
}

.install-btn {
  white-space: nowrap;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.timer-panel {
  grid-row: span 3;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 4px 0 0;
  font-size: 19px;
}

.timer-display {
  margin: 24px 0;
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(46px, 7vw, 88px);
  font-weight: 850;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}

.input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
}

.input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(37, 99, 235, 0.14);
}

.color-input {
  padding: 5px;
}

.small-select {
  width: 140px;
}

.button-row,
.button-stack {
  display: flex;
  gap: 10px;
}

.button-stack {
  flex-direction: column;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: #f8fafc;
}

.btn.danger {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.btn.wide {
  grid-column: 1 / -1;
}

.wide {
  grid-column: 1 / -1;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.quick-projects {
  display: grid;
  gap: 10px;
}

.quick-project {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
  text-align: left;
}

.quick-project.selected {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: var(--primary-dark);
  font-weight: 800;
}

.compact-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
}

.compact-stat span,
.metric span {
  color: var(--muted);
}

.compact-stat strong {
  font-size: 34px;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.rule-builder {
  display: grid;
  gap: 10px;
}

.rule-builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.condition-list {
  display: grid;
  gap: 8px;
}

.condition-row {
  display: grid;
  grid-template-columns: 116px repeat(3, minmax(0, 1fr)) 82px 34px;
  gap: 8px;
  align-items: center;
}

.condition-row .input {
  min-height: 38px;
  padding: 8px 9px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.item-main {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.item-main strong,
.item-main span {
  display: block;
}

.item-main span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.project-dot,
.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.project-dot.muted {
  background: #cbd5e1;
}

.status-dot {
  background: #cbd5e1;
}

.status-dot.ok {
  background: var(--good);
}

.status-dot.pending {
  background: var(--warn);
}

.status-dot.off {
  background: #94a3b8;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  color: var(--text);
  font-weight: 900;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 8px;
  background: #f1f5f9;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.empty {
  padding: 22px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #f8fafc;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: 26px;
}

.bar-chart {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

.bar-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 92px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.bar-row strong {
  color: var(--text);
  text-align: right;
}

.bar-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.timeline {
  margin-top: 22px;
}

.chart-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.timeline-track {
  position: relative;
  height: 38px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 8px;
  background: #e5e7eb;
}

.timeline-block {
  position: absolute;
  top: 0;
  height: 100%;
  opacity: 0.88;
}

.period-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(54px, 1fr);
  align-items: end;
  gap: 10px;
  min-height: 170px;
  overflow-x: auto;
  padding: 12px 2px 2px;
}

.period-bar {
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: end;
  justify-items: center;
  gap: 5px;
  min-width: 54px;
  height: 160px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.period-stack {
  display: flex;
  flex-direction: column-reverse;
  width: min(34px, 70%);
  min-height: 4px;
  overflow: hidden;
  border-radius: 8px 8px 4px 4px;
  background: #e5e7eb;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06);
}

.period-segment {
  width: 100%;
}

.period-bar strong {
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
}

.insights {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.insight {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.insight strong,
.insight span {
  display: block;
}

.insight span {
  margin-top: 8px;
  color: var(--muted);
}

.file-btn {
  cursor: pointer;
}

.sync-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.sync-status {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .dashboard-grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .timer-panel {
    grid-row: auto;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    top: auto;
    z-index: 10;
    height: auto;
    padding: 8px max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    border-right: 0;
  }

  .brand {
    display: none;
  }

  .nav {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
  }

  .nav-item {
    justify-content: center;
    min-height: 48px;
    padding: 7px 4px;
    font-size: 16px;
  }

  .nav-item span {
    display: none;
  }

  .content {
    padding: 20px 14px 82px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .topbar h1 {
    font-size: 25px;
  }

  .score-pill {
    min-width: 110px;
    padding: 10px;
  }

  .install-btn {
    width: 100%;
    grid-column: 1 / -1;
  }

  .two-col,
  .stats-grid,
  .insights {
    grid-template-columns: 1fr;
  }

  .timer-panel {
    grid-row: auto;
  }

  .button-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .condition-row {
    grid-template-columns: 1fr 1fr;
  }

  .condition-row .condition-remove {
    width: 100%;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .bar-row strong {
    text-align: left;
  }
}
