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

:root,
[data-theme="dark"] {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #222536;
  --border:    #2e3248;
  --text:      #e8eaf0;
  --text-dim:  #8890aa;
  --accent:    #4f8ef7;
  --on:        #2ecc71;
  --off:       #e74c3c;
  --possible:  #f39c12;
  --unknown:   #3a3f55;
  --tab-bg:    #1a1d27;
  --tab-active:#2e3a5c;
  --radius:    10px;
  --radius-sm: 5px;
}
[data-theme="light"] {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface2:  #eef1f8;
  --border:    #d0d6e8;
  --text:      #1a1d2e;
  --text-dim:  #606680;
  --accent:    #2563eb;
  --on:        #16a34a;
  --off:       #dc2626;
  --possible:  #d97706;
  --unknown:   #cbd5e1;
  --tab-bg:    #eef1f8;
  --tab-active:#ffffff;
}

html { font-size: 33.6px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0.3rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
header h1 {
  grid-column: 2;
  text-align: center;
  font-size: clamp(0.98rem, 2.8vw, 1.33rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 0 0.5rem;
}
header h1 small {
  font-size: 0.245em;
  font-weight: 400;
  color: var(--text-dim);
}
.subtitle { display: none; }
.back-link {
  grid-column: 1;
  justify-self: start;
  color: var(--text-dim);
  font-size: 0.84rem;
  white-space: nowrap;
}
.back-link:hover { color: var(--text); text-decoration: none; }
.header-spacer { grid-column: 1; }

.theme-toggle {
  grid-column: 3;
  justify-self: end;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 1.8rem;
  height: 1.8rem;
  font-size: 1.12rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}
.theme-toggle:hover { background: var(--border); }

main {
  flex: 1;
  width: 100%;
  max-width: 100%;
  padding: 0.4rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow: hidden;
}

.address-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}
.address-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 1.25rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  cursor: pointer;
}
.address-card:hover {
  background: var(--surface2);
  border-color: var(--accent);
  transform: translateY(-2px);
  text-decoration: none;
}
.card-addr  { font-size: 1.19rem; font-weight: 600; text-align: center; }
.card-group { font-size: 0.91rem; color: var(--text-dim); }
.card-group strong { color: var(--accent); }

.status-banner {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.91rem;
  line-height: 1.4;
  flex-shrink: 0;
}
.status-banner.hidden { display: none; }
.status-banner.warn  { background: rgba(243,156,18,0.15); border: 1px solid rgba(243,156,18,0.4); color: #c97b00; }
.status-banner.ok    { background: rgba(46,204,113,0.12); border: 1px solid rgba(46,204,113,0.35); color: #16a34a; }
.status-banner.info  { background: rgba(79,142,247,0.12); border: 1px solid rgba(79,142,247,0.35); color: #2563eb; }
[data-theme="dark"] .status-banner.warn { color: #f5c842; }
[data-theme="dark"] .status-banner.ok   { color: #2ecc71; }
[data-theme="dark"] .status-banner.info { color: #7ab3ff; }

.tabs {
  display: flex;
  gap: 0.2rem;
  background: var(--tab-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2rem;
  flex-shrink: 0;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.3rem 0.5rem;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 3px);
  color: var(--text-dim);
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.2;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--tab-active);
  color: var(--text);
  box-shadow: 0 1px 6px rgba(0,0,0,0.25);
}
.tab-date {
  font-size: 0.77rem;
  font-weight: 400;
  color: var(--text-dim);
  white-space: nowrap;
}
.tab.active .tab-date { color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: flex; flex-direction: column; gap: 0.45rem; }

.timeline-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  min-height: 50px;
}
.timeline-grid.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
}

.tl-bar-wrap {
  position: relative;
}
.tl-bar {
  display: flex;
  height: 78px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  gap: 0;
}
.tl-cell {
  flex: 1;
  transition: opacity 0.1s;
  cursor: default;
}
.tl-cell:hover { opacity: 0.75; }

.tl-hour-wrap {
  flex: 2;
  display: flex;
  position: relative;
}
.tl-hour-wrap + .tl-hour-wrap {
  border-left: 1px solid rgba(0,0,0,0.25);
}
[data-theme="light"] .tl-hour-wrap + .tl-hour-wrap {
  border-left-color: rgba(0,0,0,0.15);
}
.tl-cell.on      { background: var(--on); }
.tl-cell.off     { background: var(--off); }
.tl-cell.possible {
  background: repeating-linear-gradient(
    45deg,
    var(--possible), var(--possible) 3px,
    rgba(243,156,18,0.35) 3px, rgba(243,156,18,0.35) 6px
  );
}
.tl-cell.unknown { background: var(--unknown); }

.tl-now {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: white;
  box-shadow: 0 0 4px rgba(0,0,0,0.6);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 2;
}
[data-theme="light"] .tl-now {
  background: #111;
  box-shadow: 0 0 4px rgba(0,0,0,0.25);
}
.tl-now-label {
  position: absolute;
  top: -1.2rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.63rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  background: var(--surface);
  padding: 0 2px;
  border-radius: 2px;
}

.tl-labels {
  position: relative;
  height: 14px;
  margin-top: 3px;
}
.tl-hour-label {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-dim);
  user-select: none;
}

.off-block {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.off-block:empty { display: none; }
.off-block-title {
  font-size: 0.77rem;
  color: var(--text-dim);
  font-weight: 600;
}
.off-block-item {
  font-size: 0.84rem;
  color: var(--text);
  font-weight: 500;
  line-height: 1.5;
}

.inline-status {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.98rem;
}
.inline-status.warn  { color: #c97b00; }
.inline-status.ok    { color: #16a34a; }
.inline-status.info  { color: #2563eb; }
.inline-status.error { color: #dc2626; }
[data-theme="dark"] .inline-status.warn  { color: #f5c842; }
[data-theme="dark"] .inline-status.ok    { color: #2ecc71; }
[data-theme="dark"] .inline-status.info  { color: #7ab3ff; }
[data-theme="dark"] .inline-status.error { color: #e74c3c; }

.updated-at {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: right;
  flex-shrink: 0;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) {
  html { font-size: 25.2px; }
  body { overflow: auto; height: auto; min-height: 100vh; }
  .tl-bar { height: 60px; }
  .tab-date { display: none; }
}
