.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 200px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--gap);
  box-sizing: border-box;
  z-index: 110;
  transform: translateX(-100%);
  transition: transform 0.15s ease;
}
.app[data-sidebar="shown"] .sidebar {
  transform: translateX(0);
  box-shadow: 2px 0 14px rgba(0,0,0,0.35);
}
.sidebar-toggle {
  position: fixed;
  top: 12px; left: 12px;
  z-index: 120;
  width: 38px; height: 38px;
  padding: 0; font-size: 1.1rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.4);
}
.sidebar-backdrop[hidden] { display: none; }
.sidebar-brand { font-size: 1.3rem; font-weight: 600; margin-bottom: var(--gap); padding: 0 8px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar-nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: var(--radius);
}
.sidebar-nav a:hover { background: var(--surface); color: var(--text); }
.sidebar-nav a.active { background: var(--surface-2); color: var(--accent); }

.sidebar-footer { display: flex; justify-content: flex-end; }

.view { flex: 1; padding: 56px 24px 24px; overflow: auto; }

.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--gap);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}

/* Responsive: narrow sidebar overlay on small viewports */
@media (max-width: 640px) {
  .sidebar { width: 80%; max-width: 240px; }
}

.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--gap);
}
.service-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  text-align: center;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s;
}
.service-card:hover { border-color: var(--accent); }
.service-card img { width: 32px; height: 32px; }
.service-card .name { font-weight: 500; font-size: 0.9rem; }
.service-card .status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.online { background: #10b981; }
.status-dot.offline { background: #ef4444; }
.status-dot.pending { background: var(--text-muted); }

.category-group { margin-bottom: 20px; }
.category-group h3 { color: var(--text-muted); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.05em; margin: 0 0 8px; }
.muted { color: var(--text-muted); }

table.monitor {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
table.monitor th, table.monitor td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
table.monitor th { background: var(--surface-2); color: var(--text-muted); font-weight: 500; }
.spark { display: inline-block; height: 20px; width: 80px; vertical-align: middle; }

.widget-clock { text-align: center; padding: 24px; }
.widget-clock .time { font-size: 2.5rem; font-weight: 200; }
.widget-clock .date { font-size: 0.9rem; margin-top: 4px; }

.home-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}
.home-edit-btn { font-size: 0.85rem; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 120px;
  grid-auto-flow: dense;
  gap: var(--gap);
}
.home-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.home-cell .cell-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.home-cell .card { height: 100%; box-sizing: border-box; }

/* Per-widget accent colors */
.home-cell[data-widget="clock"]        { --cell-accent: #f59e0b; }
.home-cell[data-widget="rss"]          { --cell-accent: #f97316; }
.home-cell[data-widget="youtube"]      { --cell-accent: #ef4444; }
.home-cell[data-widget="calendar"]     { --cell-accent: #3b82f6; }
.home-cell[data-widget="system-stats"] { --cell-accent: #14b8a6; }
.home-cell[data-widget="service-grid"] { --cell-accent: #6366f1; }

.home-cell .card {
  border-top: 3px solid var(--cell-accent, var(--border));
}
.home-cell .card > h3,
.home-cell .yt-link-card.card > h3 { color: var(--cell-accent, var(--text)); }
.home-cell[data-widget="clock"] .widget-clock .time { color: var(--cell-accent); }
.home-cell[data-widget="service-grid"] .category-group h3 { color: var(--cell-accent); }
.home-cell[data-widget="service-grid"] .service-card:hover { border-color: var(--cell-accent); }

.size-1x1 { grid-column: span 1; grid-row: span 1; }
.size-1x2 { grid-column: span 1; grid-row: span 2; }
.size-2x1 { grid-column: span 2; grid-row: span 1; }
.size-4x1 { grid-column: span 4; grid-row: span 1; }
.size-2x2 { grid-column: span 2; grid-row: span 2; }
.size-3x2 { grid-column: span 3; grid-row: span 2; }
.size-4x2 { grid-column: span 4; grid-row: span 2; }
.size-4x4 { grid-column: span 4; grid-row: span 4; }

@media (max-width: 720px) {
  .home-grid { grid-template-columns: repeat(2, 1fr); }
  .size-4x1, .size-4x2, .size-3x2, .size-4x4 { grid-column: span 2; }
}

.cell-edit {
  display: none;
  gap: 8px;
  align-items: center;
  padding: 4px 8px;
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 1px solid var(--border);
}
.cell-edit .cell-name { font-size: 0.8rem; font-weight: 500; flex: 1; }
.cell-edit .cell-size { font-size: 0.8rem; padding: 2px 6px; }
.home-grid.editing .cell-edit { display: flex; }
.home-grid.editing .home-cell { outline: 1px dashed var(--border); outline-offset: -1px; }
.home-grid.editing .cell-body { opacity: 0.55; }

/* Calendar widget */
.cal-card .cal-list { list-style: none; margin: 8px 0 0; padding: 0; }
.cal-day { padding: 6px 0; border-bottom: 1px solid var(--border); }
.cal-day:last-child { border-bottom: none; }
.cal-day-label {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 4px;
}
.cal-events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.cal-event {
  display: grid;
  grid-template-columns: 10px auto 1fr;
  align-items: baseline;
  gap: 6px;
  font-size: 0.85rem;
  line-height: 1.3;
}
.cal-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 5px; justify-self: start; align-self: start;
  box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 5%, transparent);
}
.cal-time { font-variant-numeric: tabular-nums; color: var(--text-muted); white-space: nowrap; }
.cal-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-loc { grid-column: 2 / -1; font-size: 0.78rem; }

.admin-section { margin-bottom: 32px; }
.admin-section h2 { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.form-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.form-row input { flex: 1; }
table.admin { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
table.admin th, table.admin td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
table.admin th { background: var(--surface-2); color: var(--text-muted); font-weight: 500; }
.danger { color: #ef4444; }

/* YouTube page */
.yt-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.yt-head h1 { margin: 0; }
.yt-head #yt-refresh { margin-left: auto; }
.yt-tabs { display: flex; gap: 4px; }
.yt-tab { background: transparent; }
.yt-tab.active { border-color: var(--accent); color: var(--accent); }
.yt-warn { margin: 0 0 12px; font-size: 0.85rem; }

.yt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--gap);
}
.yt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
}
.yt-card:hover, .yt-card:focus { border-color: var(--accent); outline: none; transform: translateY(-2px); }
.yt-thumb { aspect-ratio: 16 / 9; background: var(--surface-2); overflow: hidden; }
.yt-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.yt-thumb-empty { width: 100%; height: 100%; }
.yt-card-body { padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.yt-card-body h3 { margin: 0; font-size: 0.95rem; line-height: 1.3; }
.yt-channel { font-size: 0.8rem; margin: 0; }
.yt-card-summary { font-size: 0.85rem; line-height: 1.4; margin: 4px 0 0; color: var(--text); }

/* modal */
.yt-modal { position: fixed; inset: 0; z-index: 1000; }
.yt-modal[hidden] { display: none; }
.yt-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.yt-modal-card {
  position: relative;
  margin: 4vh auto 0;
  width: min(900px, 94vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.yt-close {
  position: absolute; top: 8px; right: 10px; z-index: 2;
  width: 34px; height: 34px; padding: 0; font-size: 1.3rem; line-height: 1;
  background: rgba(0,0,0,0.5); color: #fff; border-color: transparent;
}
.yt-player { aspect-ratio: 16 / 9; width: 100%; background: #000; }
.yt-player iframe { width: 100%; height: 100%; border: 0; display: block; }
.yt-modal-meta { padding: 16px 18px 20px; }
.yt-modal-meta h2 { margin: 0 0 4px; font-size: 1.15rem; }
.yt-summary { margin: 12px 0; font-size: 0.92rem; line-height: 1.5; }
.yt-actions { margin-top: 8px; }
.yt-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.yt-link-card { text-decoration: none; color: var(--text); display: block; transition: border-color 0.15s; }
.yt-link-card:hover { border-color: var(--accent); }
.yt-link-card h3 { margin: 0 0 4px; }
.yt-link-card p { margin: 0; }
