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

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface-2:   #1c2128;
  --border:      #30363d;
  --border-2:    #484f58;
  --text:        #e6edf3;
  --muted:       #8b949e;
  --accent:      #388bfd;
  --accent-dim:  rgba(56,139,253,.15);
  --success:     #3fb950;
  --danger:      #f85149;
  --warning:     #d29922;
  --radius:      8px;
  --nav-h:       50px;
  --sticky-h:    88px;
  --panel-w:     380px;
  --shadow:      0 4px 16px rgba(0,0,0,.5);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

/* Sticky overlay — transparent full-screen grid, sits above views */
#sticky-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--nav-h);
  z-index: 50;
  pointer-events: none;
}

/* Grid container — pointer-events toggled via JS edit mode */
#sticky-overlay .grid-stack {
  pointer-events: none;
  width: 100%;
  min-height: 100%;
  background: transparent;
}

#sticky-overlay.editing .grid-stack {
  pointer-events: all;
  background: repeating-linear-gradient(
    90deg,
    rgba(56,139,253,.04) 0px,
    rgba(56,139,253,.04) 1px,
    transparent 1px,
    transparent calc(100% / 12)
  );
}

#sticky-overlay .grid-stack-item {
  pointer-events: all;
}

#sticky-overlay .grid-stack-item-content {
  background: rgba(22, 27, 34, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#main-area {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--nav-h);
  overflow: hidden;
}

#views-container {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ── Views ───────────────────────────────────────────────────────────────── */

.view-container {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s ease;
  overflow: auto;
  padding: 8px;
}

.view-container.active {
  opacity: 1;
  pointer-events: all;
}

.view-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  gap: 1rem;
}

.view-empty p { font-size: 1rem; }

/* ── Nav bar ─────────────────────────────────────────────────────────────── */

#nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  z-index: 100;
}

#view-indicators {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 60px;
}

.view-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-2);
  cursor: pointer;
  transition: background .2s, transform .2s;
}

.view-dot.active {
  background: var(--accent);
  transform: scale(1.25);
}

.view-dot:hover:not(.active) { background: var(--muted); }

#nav-center {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

#current-view-name {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text);
  min-width: 120px;
  text-align: center;
}

#nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  justify-content: flex-end;
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  padding: 5px 10px;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, border-color .15s, background .15s;
}

.nav-btn:hover {
  color: var(--text);
  border-color: var(--border-2);
  background: var(--surface-2);
}

#timer-track {
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

#timer-progress {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 100%;
  transition: width linear;
}

/* ── Config panel ────────────────────────────────────────────────────────── */

#config-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: var(--nav-h);
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#config-panel.open { transform: translateX(0); }

#config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#config-header h2 { font-size: 1rem; font-weight: 600; }

#btn-close-panel {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}

#btn-close-panel:hover { color: var(--text); background: var(--surface-2); }

#config-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .8125rem;
  font-weight: 500;
  padding: 10px 0;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

#config-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Config UI elements ──────────────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-header h3 { font-size: .875rem; font-weight: 600; }

.item-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-card-info { flex: 1; min-width: 0; }
.item-card-title {
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-card-sub {
  font-size: .75rem;
  color: var(--muted);
  margin-top: 2px;
}

.item-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
  font-size: .8125rem;
  padding: 4px 7px;
  transition: color .15s, border-color .15s, background .15s;
}

.btn-icon:hover { color: var(--text); background: var(--surface); border-color: var(--border-2); }
.btn-icon.danger:hover { color: var(--danger); border-color: var(--danger); background: rgba(248,81,73,.1); }

.btn-add {
  width: 100%;
  background: none;
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: .8125rem;
  padding: 8px;
  margin-top: 6px;
  transition: color .15s, border-color .15s, background .15s;
}

.btn-add:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

.badge {
  display: inline-block;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 6px;
  text-transform: uppercase;
}

.badge-blue { background: rgba(56,139,253,.2); color: var(--accent); }
.badge-green { background: rgba(63,185,80,.2); color: var(--success); }
.badge-gray { background: rgba(139,148,158,.15); color: var(--muted); }

.hint { font-size: .8rem; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }

/* ── Dialog (modal) ──────────────────────────────────────────────────────── */

#edit-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  color: var(--text);
  max-width: 480px;
  width: 92vw;
  padding: 0;
}

#edit-dialog::backdrop {
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(2px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h3 { font-size: 1rem; font-weight: 600; }

.dialog-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  border-radius: 4px;
  transition: color .15s;
}

.dialog-close:hover { color: var(--text); }

#dialog-body {
  padding: 16px 20px;
  max-height: 60vh;
  overflow-y: auto;
}

.dialog-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ── Form fields ─────────────────────────────────────────────────────────── */

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="url"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .9rem;
  padding: 7px 10px;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}

.field textarea { resize: vertical; min-height: 80px; }

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56,139,253,.12);
}

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.toggle-row label { color: var(--text); text-transform: none; font-size: .875rem; letter-spacing: 0; }

/* Toggle switch */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border-2);
  border-radius: 10px;
  cursor: pointer;
  transition: background .2s;
}

.toggle input:checked + .toggle-track { background: var(--accent); }

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}

.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 600;
  padding: 7px 16px;
  transition: opacity .15s;
}

.btn-primary:hover { opacity: .87; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: .875rem;
  padding: 7px 16px;
  transition: color .15s, border-color .15s;
}

.btn-ghost:hover { color: var(--text); border-color: var(--border-2); }

/* ── Widgets ─────────────────────────────────────────────────────────────── */

.grid-stack-item-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.widget {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.widget-header {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  gap: 6px;
  flex-shrink: 0;
}

.widget-title {
  flex: 1;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-btn {
  background: none;
  border: none;
  color: var(--border-2);
  cursor: pointer;
  font-size: .75rem;
  padding: 2px 5px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity .15s, color .15s;
}

.widget-header:hover .widget-btn { opacity: 1; }
.widget-btn:hover { color: var(--text); }
.widget-btn.widget-delete:hover { color: var(--danger); }

.widget-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Clock widget */
.clock-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 12px;
  text-align: center;
}

.clock-time {
  font-size: clamp(1.5rem, 4vw, 3.5rem);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  line-height: 1;
}

.clock-date {
  font-size: clamp(.75rem, 1.5vw, 1rem);
  color: var(--muted);
  margin-top: 6px;
}

.clock-tz {
  font-size: .7rem;
  color: var(--border-2);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* External / iframe widget */
.widget-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Recurring events feed */
.events-feed {
  list-style: none;
  padding: 0;
  overflow-y: auto;
  height: 100%;
}

.events-feed li {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  font-size: .8125rem;
  line-height: 1.4;
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.events-feed li:last-child { border-bottom: none; }

.event-time {
  color: var(--muted);
  font-size: .75rem;
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.event-title { font-weight: 500; }
.event-desc { color: var(--muted); font-size: .75rem; }

.upcoming-section {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.upcoming-section h4 {
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 8px 12px 4px;
  flex-shrink: 0;
}

.upcoming-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.upcoming-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: .8125rem;
  gap: 8px;
}

.upcoming-list .up-name { font-weight: 500; }
.upcoming-list .up-when { color: var(--muted); font-size: .75rem; white-space: nowrap; }

/* Empty widget placeholder */
.widget-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--border-2);
  font-size: .875rem;
  font-style: italic;
}

/* ── Toast notifications ─────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 500;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: .875rem;
  box-shadow: var(--shadow);
  animation: toastIn .2s ease forwards;
  white-space: nowrap;
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger); }
.toast.info    { border-color: var(--accent);  color: var(--accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Gridstack overrides ─────────────────────────────────────────────────── */

.grid-stack { background: transparent; }

.grid-stack-item.ui-draggable-dragging .grid-stack-item-content,
.grid-stack-item.ui-resizable-resizing .grid-stack-item-content {
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
  border-color: var(--accent);
}

.grid-stack-placeholder > .placeholder-content {
  background: var(--accent-dim);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── RSS widget ──────────────────────────────────────────────────────────── */

.rss-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.rss-feed-title {
  font-size: .7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rss-feed {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.rss-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}

.rss-item:hover { background: var(--surface-2); }
.rss-item:last-child { border-bottom: none; }

.rss-item-title {
  font-size: .8125rem;
  font-weight: 500;
  line-height: 1.35;
  margin-bottom: 3px;
}

.rss-item-snippet {
  font-size: .75rem;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rss-item-meta {
  display: flex;
  gap: 8px;
  font-size: .7rem;
  color: var(--border-2);
}

.rss-error {
  padding: 12px;
  color: var(--danger);
  font-size: .8rem;
}

/* ── Sentry widget ───────────────────────────────────────────────────────── */

.sentry-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sentry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sentry-project-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.sentry-count {
  font-size: .75rem;
  color: var(--border-2);
}

.sentry-feed {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.sentry-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: default;
  transition: background .15s;
}

.sentry-item:hover { background: var(--surface-2); }
.sentry-item:last-child { border-bottom: none; }

.sentry-badge {
  flex-shrink: 0;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 2px;
}

.sentry-badge-error   { background: rgba(248,81,73,.2);  color: #f85149; }
.sentry-badge-warning { background: rgba(210,153,34,.2); color: #d29922; }
.sentry-badge-info    { background: rgba(56,139,253,.2); color: #388bfd; }
.sentry-badge-debug   { background: rgba(139,148,158,.15); color: var(--muted); }

.sentry-item-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sentry-item-title {
  font-size: .8125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sentry-item-meta {
  font-size: .75rem;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
}

.sentry-item-time {
  color: var(--border-2);
  font-size: .7rem;
  margin-left: auto;
}

/* ── Event promotion badge ───────────────────────────────────────────────── */

#promotion-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: .8125rem;
  color: var(--accent);
  z-index: 300;
  display: none;
  animation: toastIn .2s ease;
  white-space: nowrap;
}
