/* ============================================================
   SHELL.CSS – Design Tokens + Grid + Tile + Login
   ============================================================ */

:root {
  /* Backgrounds */
  --color-bg-primary:    #0f0f0f;
  --color-bg-secondary:  #1a1a1a;
  --color-bg-tertiary:   #242424;

  /* Borders */
  --color-border:        #2a2a2a;
  --color-border-light:  #333333;

  /* Text */
  --color-text-primary:  #e8e8e8;
  --color-text-secondary:#9a9a9a;
  --color-text-tertiary: #666666;

  /* Semantic */
  --color-green:         #059669;
  --color-green-light:   #C0DD97;
  --color-red:           #DC2626;
  --color-red-light:     #F7C1C1;
  --color-amber:         #F59E0B;
  --color-blue:          #1D4ED8;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* Spacing / Radius */
  --radius-sm:  3px;
  --radius-md:  6px;
  --radius-lg:  10px;

  /* Tile */
  --tile-header-height: 36px;
  --tile-padding:       10px;
}

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

html, body {
  height: 100%;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Login Screen ───────────────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-primary);
  z-index: 9999;
}

#login-screen.hidden {
  display: none;
}

.login-card {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 40px 48px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-logo {
  text-align: center;
}

.login-logo h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: 0.03em;
}

.login-logo p {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-top: 4px;
}

.login-card input[type="password"] {
  width: 100%;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-card input[type="password"]:focus {
  border-color: var(--color-blue);
}

.login-card button {
  width: 100%;
  background: var(--color-blue);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.login-card button:hover {
  opacity: 0.85;
}

.login-error {
  font-size: 12px;
  color: var(--color-red);
  text-align: center;
  min-height: 16px;
}

/* ── Dashboard Shell ────────────────────────────────────────── */
#dashboard {
  display: none;
  flex-direction: column;
  height: 100vh;
}

#dashboard.visible {
  display: flex;
}

/* Top Bar */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 16px;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-topbar {
  background: transparent;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-topbar:hover {
  color: var(--color-text-primary);
  border-color: var(--color-text-tertiary);
}

/* Grid Area */
#grid-area {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* ── GridStack overrides ─────────────────────────────────────── */
.grid-stack {
  background: transparent;
}

.grid-stack-item-content {
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* ── Tile ─────────────────────────────────────────────────── */
.tile {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.tile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--tile-header-height);
  padding: 0 10px;
  background: var(--color-bg-tertiary);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  cursor: move;
  user-select: none;
}

.tile-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
}

.tile-controls button {
  background: transparent;
  border: none;
  color: var(--color-text-tertiary);
  font-size: 13px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

.tile-controls button:hover {
  color: var(--color-text-primary);
  background: var(--color-border-light);
}

.tile-controls button.active {
  color: var(--color-amber);
}

.tile-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

/* Paused overlay */
.tile.paused .tile-content::after {
  content: 'Paused';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 15, 0.75);
  color: var(--color-text-tertiary);
  font-size: 12px;
  letter-spacing: 0.05em;
}

/* Loading state */
.tile-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-tertiary);
  font-size: 12px;
  gap: 8px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border-light);
  border-top-color: var(--color-text-tertiary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error state */
.tile-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-red);
  font-size: 12px;
  padding: 16px;
  text-align: center;
}

/* ── Widget Manager Panel ────────────────────────────────────── */
#widget-manager {
  position: fixed;
  top: 44px;
  right: 0;
  width: 280px;
  height: calc(100vh - 44px);
  background: var(--color-bg-secondary);
  border-left: 1px solid var(--color-border);
  z-index: 500;
  display: none;
  flex-direction: column;
  overflow-y: auto;
}

#widget-manager.open {
  display: flex;
}

.wm-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.wm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  font-size: 12px;
  color: var(--color-text-primary);
}

.wm-item-controls {
  display: flex;
  gap: 6px;
}

.wm-toggle {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-light);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.wm-toggle.on {
  background: var(--color-green);
  border-color: var(--color-green);
  color: #fff;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-tertiary);
}

/* ── Light theme overrides ───────────────────────────────────── */
[data-theme="light"] {
  --color-bg-primary:    #f0f2f5;
  --color-bg-secondary:  #ffffff;
  --color-bg-tertiary:   #e8eaed;
  --color-border:        #d0d3d8;
  --color-border-light:  #bbbfc6;
  --color-text-primary:  #1a1a1a;
  --color-text-secondary:#4a4a4a;
  --color-text-tertiary: #7a7a7a;
}

/* ── Utility ─────────────────────────────────────────────────── */
.hidden { display: none !important; }
