.shutter-row.busy {
  opacity: 0.65;
}

.shutter-row.busy .shutter-label::after {
  content: " …";
  color: var(--muted);
  font-weight: 400;
}

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --border: #d8dee6;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --success: #059669;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --touch: 44px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a {
  color: var(--accent);
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(244, 246, 248, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  margin: 0;
  font-size: 1.125rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logout-link {
  min-height: var(--touch);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.main-content {
  padding: 12px 12px 88px;
  max-width: 640px;
  margin: 0 auto;
}

.group-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.group-card h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

.shutter-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shutter-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.shutter-label {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.25;
}

.shutter-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: var(--touch);
  height: var(--touch);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn.up:hover { background: #ecfdf5; color: var(--success); }
.icon-btn.down:hover { background: #eff6ff; color: var(--accent); }
.icon-btn.stop:hover { background: #fef2f2; color: var(--danger); }
.icon-btn.position:hover { background: #f5f3ff; color: #6d28d9; }

.position-wrap {
  position: relative;
  flex-shrink: 0;
}

.preset-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 15;
  min-width: 160px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
}

.preset-menu.open {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preset-menu-item {
  min-height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}

.preset-menu-item:hover {
  background: var(--bg);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.status-check {
  width: var(--touch);
  height: var(--touch);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--success);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.2s, transform 0.2s;
}

.status-check.visible {
  opacity: 1;
  transform: scale(1);
}

.lock-btn {
  width: var(--touch);
  height: var(--touch);
  flex-shrink: 0;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lock-btn.locked {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #93c5fd;
}

.lock-btn svg {
  width: 18px;
  height: 18px;
}

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  padding: 12px 16px;
  border-radius: var(--radius);
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 20;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

.login-card label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  font-weight: 600;
}

.login-card input {
  width: 100%;
  min-height: var(--touch);
  margin-bottom: 14px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
}

.login-card button {
  width: 100%;
  min-height: var(--touch);
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fef2f2;
  color: var(--danger);
  font-size: 0.875rem;
}

.env-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.env-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 500;
}

.env-metric {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.env-metric[data-metric="condition"] {
  flex: 1 1 100%;
  font-weight: 400;
  color: var(--muted);
}

.env-arc-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.env-time {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 2.75rem;
}

.env-time--rise {
  text-align: right;
}

.env-time--set {
  text-align: left;
}

.env-arc {
  flex: 1;
  height: 24px;
  min-width: 0;
  overflow: visible;
}

.env-arc-track {
  stroke: var(--border);
  stroke-width: 2;
  stroke-linecap: round;
}

.env-card--night .env-arc-track {
  opacity: 0.6;
}

.env-arc-dot {
  fill: var(--accent);
}

.env-card--night .env-arc-dot {
  fill: var(--muted);
}

.auto-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.auto-card-toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.auto-card-toggle:disabled {
  cursor: default;
}

.auto-summary {
  flex: 1;
  min-width: 0;
}

.auto-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 0.9rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.auto-chip {
  color: var(--text);
}

.auto-chip--muted {
  color: var(--muted);
  font-weight: 400;
}

.auto-chip--down {
  color: var(--accent);
}

.auto-chip--up {
  color: var(--success);
}

.auto-empty {
  font-size: 0.9rem;
  color: var(--muted);
}

.auto-chevron {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.auto-card[aria-expanded="true"] .auto-chevron {
  transform: rotate(180deg);
}

.auto-card:not(.auto-card--has-events) .auto-chevron {
  visibility: hidden;
}

.auto-history-list {
  border-top: 1px solid var(--border);
  padding: 8px 14px 12px;
}

.auto-history-list[hidden] {
  display: none;
}

.auto-history-list .auto-row + .auto-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

@media (min-width: 640px) {
  .group-row {
    grid-template-columns: 1fr 1fr;
  }
}
