/* Mission Control Dashboard Styles
   This stylesheet overlays the existing themes and component styles to
   provide a scalable, modular dashboard layout. It is intentionally light
   on color definitions and reuses the CSS variables defined in app.html
   for both light and dark themes.
*/

/* ========== Layout Shell ========== */
:root {
  --mc-gap-xs: 6px;
  --mc-gap-sm: 10px;
  --mc-gap-md: 14px;
  --mc-gap-lg: 18px;
  --mc-gap-xl: 24px;

  --mc-radius-sm: 6px;
  --mc-radius-md: 8px;
  --mc-radius-lg: 12px;

  --mc-shadow: 0 2px 6px rgba(0,0,0,0.08);
  --mc-shadow-lg: 0 6px 18px rgba(0,0,0,0.12);
}

/* Allow the main content to behave like a dashboard surface. */
.main-content {
  display: block;
}

/* Sticky dock for the primary panel (Server Reset). Keeps it visible while scrolling). */
#serverResetBanner {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(1.1) blur(6px);
}

/* Apply edge separators so the sticky dock reads as a docked element */
#serverResetBanner::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: var(--border-color);
  opacity: 0.75;
}

/* ========== Dashboard Grid ========== */
/* Re-style the existing .grid container as a dashboard grid that auto-fits cards. */
.grid,
.dashboard-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--mc-gap-md);
  align-content: start;
}

/* Large screens: increase minimum card width for richer layouts */
@media (min-width: 1440px) {
  .grid, .dashboard-grid {
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  }
}

/* Small screens: single column stacking */
@media (max-width: 768px) {
  .grid, .dashboard-grid {
    grid-template-columns: 1fr !important;
    gap: var(--mc-gap-sm) !important;
  }
}

/* Optional span utilities for future custom sizing (opt-in per card) */
.card.span-2 { grid-column: span 2; }
.card.span-3 { grid-column: span 3; }
.card.span-4 { grid-column: span 4; }
@media (max-width: 1024px) {
  .card[class*='span-'] { grid-column: span 1 !important; }
}

/* ========== Card Enhancements ========== */
.card {
  border-radius: var(--mc-radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--mc-shadow);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--mc-shadow-lg);
}

/* Card header pattern (opt-in via .card-header/.card-title if used later) */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary, var(--text));
}

/* ========== Mission-Control Accents ========== */
/* Subtle top accent bar for cards (already exists via ::before in app.css;
   keep consistent but slightly thicker for the dashboard feel). */
.card::before {
  height: 3px !important;
  opacity: 0.9 !important;
}

/* Toolbar row (optional) */
.dashboard-toolbar {
  display: flex;
  align-items: center;
  gap: var(--mc-gap-sm);
  margin: 4px 0 var(--mc-gap-sm) 0;
}
.dashboard-toolbar .chip,
.dashboard-toolbar .btn {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--mc-radius-sm);
  border: 1px solid var(--border-color);
  background: var(--card-hover);
  color: var(--text-secondary);
  font-weight: 600;
}
.dashboard-toolbar .btn.is-active,
.dashboard-toolbar .chip.is-active {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* Filter/hide utility */
.hidden { display: none !important; }

/* Core-only mode: show only cards marked as .core-panel */
body.show-core-only .grid .card:not(.core-panel),
body.show-core-only .dashboard-grid .card:not(.core-panel) {
  display: none !important;
}

/* Social-only mode: show ONLY the IC Chat card */
/* Hide IC Chat by default in all non-social layouts */
.grid #icChatCard,
.dashboard-grid #icChatCard {
  display: none;
}
/* In social-only, hide everything else and show IC Chat */
body.show-social-only .grid .card,
body.show-social-only .dashboard-grid .card {
  display: none !important;
}
body.show-social-only .grid #icChatCard,
body.show-social-only .dashboard-grid #icChatCard {
  display: block !important;
}
/* Social-only: use single column and center content */
@media (min-width: 768px) {
  body.show-social-only .grid,
  body.show-social-only .dashboard-grid {
    grid-template-columns: minmax(320px, 800px) !important;
    justify-content: center;
  }
}

/* Density toggle: Compact mode to fit more cards per viewport */
.dashboard-compact .grid,
.dashboard-compact .dashboard-grid {
  gap: var(--mc-gap-sm);
}
/* Desktop: fixed 3 columns for a 3xN compact feel */
@media (min-width: 1024px) {
  .dashboard-compact .grid,
  .dashboard-compact .dashboard-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}
/* Neutralize span utilities in compact so the grid stays 3 columns */
.dashboard-compact .card[class*='span-'] { grid-column: span 1 !important; }

.dashboard-compact .card { padding: 10px; }
.dashboard-compact .card h2 { font-size: 1rem; }
.dashboard-compact .timer-title { font-size: 0.95rem; }
.dashboard-compact .timer-display { font-size: 1rem; }

/* Layout #2: fixed 2x3 grid on desktop/tablet */
body.dashboard-two-by-three .grid,
body.dashboard-two-by-three .dashboard-grid {
  grid-template-columns: repeat(2, 1fr) !important;
  gap: var(--mc-gap-md) !important;
}
/* Neutralize any spans so panels behave as uniform tiles */
body.dashboard-two-by-three .card[class*='span-'] { grid-column: span 1 !important; }
/* Ensure IC Chat doesn't force wide or re-order in this layout */
body.dashboard-two-by-three .ic-chat-card { grid-column: span 1 !important; order: 0 !important; }
/* Ensure Custom Timers doesn't span full width in this layout */
body.dashboard-two-by-three #customTimersCard { grid-column: span 1 !important; }

/* Core-only: Desktop fixed 2 columns (side-by-side) with span neutralized */
@media (min-width: 1024px) {
  body.show-core-only .grid,
  body.show-core-only .dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--mc-gap-md);
  }
  body.show-core-only .card[class*='span-'] { grid-column: span 1 !important; }
}
/* Mobile fallback for both modes: single column */
@media (max-width: 768px) {
  body.show-core-only .grid, body.show-core-only .dashboard-grid,
  .dashboard-compact .grid, .dashboard-compact .dashboard-grid,
  body.dashboard-two-by-three .grid, body.dashboard-two-by-three .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ========== Dock awareness spacing ========== */
/* Add breathing room below the sticky dock before the grid begins */
#serverResetBanner + .grid,
#serverResetBanner + .dashboard-grid {
  margin-top: var(--mc-gap-md);
}

/* ========== Readability Tweaks ========== */
/* Ensure text contrast and sizing are consistent in widgets */
.card h2 {
  font-size: 1.1rem;
  line-height: 1.2;
}
.card p,
.card li,
.card label,
.card .info-label,
.card .time-note {
  font-size: 0.92rem;
}

/* ========== Status Chips ========== */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-hover);
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.status-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.status-chip .dot.success { background: var(--success); }
.status-chip .dot.warn { background: var(--warning); }
.status-chip .dot.danger { background: var(--danger); }

/* ========== Panel Variants (optional) ========== */
.panel-critical {
  border-color: rgba(244,67,54,0.4);
}
.panel-info {
  border-color: rgba(33,150,243,0.35);
}
.panel-success {
  border-color: rgba(46,125,50,0.45);
}

/* ========== Sticky header for mission control (optional future) ========== */
/* header is outside main grid; leave styling to app.html themes */

/* ========== Scroll behavior ========== */
/* Smoothen out mouse wheel / touch scroll on dashboards */
html { scroll-behavior: smooth; }

/* ========== Server Reset Panel specific micro-tweaks ========== */
#serverResetBanner .server-info {
  border-radius: var(--mc-radius-sm);
}
#serverResetBanner .reset-timers .reset-timer {
  border-radius: var(--mc-radius-sm);
}

/* ========== IC Chat Styles ========== */
#icChatCard {
  display: flex;
  flex-direction: column;
  min-height: 320px;
}
#icChatCard h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
#icChatMessages {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--mc-radius-sm);
  padding: 8px;
}
.ic-msg {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  padding: 6px 4px;
}
.ic-who {
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}
.ic-bubble {
  background: var(--card-hover);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px 32px 8px 10px; /* space on right for actions */
  color: var(--text);
  white-space: pre-wrap; /* preserve line breaks */
  word-break: break-word; /* prevent overflow */
  position: relative;
}
.ic-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.ic-delete { border: none; background: transparent; color: var(--text-secondary); cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.ic-delete:hover { color: var(--danger); background: rgba(244,67,54,0.08); }
.ic-delete:focus { outline: 2px solid var(--danger); outline-offset: 2px; }
.ic-delete i { pointer-events: none; }
.ic-time {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.ic-composer {
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 8px;
  align-items: end;
}
#icChatAlias,
#icChatTextarea {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: var(--mc-radius-sm);
}
#icChatTextarea {
  resize: none; /* auto-grow via JS */
  min-height: 38px;
  max-height: 160px;
  padding: 8px 10px;
  line-height: 1.3;
}
#icChatSendBtn {
  white-space: nowrap;
}

/* Custom Timer Stepper: ensure 3-digit minutes (e.g., 100) are not clipped */
.custom-stepper {
  /* Force the middle input to have a minimum width while still flexible */
  grid-template-columns: auto minmax(92px, 1fr) auto !important;
}
.custom-stepper input[type="number"] {
  min-width: 92px;
  padding: 0 10px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  box-sizing: border-box;
}
/* Hide native spin buttons to free horizontal space */
.custom-stepper input[type="number"]::-webkit-outer-spin-button,
.custom-stepper input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.custom-stepper input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Prefer IC Chat to appear early and wider */
.ic-chat-card { grid-column: span 2; order: -1; }

/* Custom Timers: keep preset chips in a single line to avoid tall card */
#customChips {
  flex-wrap: nowrap !important; /* override inline wrap */
  overflow-x: auto;
  gap: 6px; /* slightly tighter spacing */
  padding-bottom: 2px; /* room for scrollbar */
}
/* Subtle horizontal scrollbar styling */
#customChips::-webkit-scrollbar { height: 6px; }
#customChips::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

/* On desktop, make Custom Timers span full width so its height doesn't stretch other rows */
/* Make Custom Timers always span the full grid width */
#customTimersCard { grid-column: 1 / -1; }

/* Ensure the Custom Timer control row (outer grid just before end of #customCard) can shrink/stack */
#customCard { overflow: visible; }
/* Replace the fixed grid with a wrapping flex layout for resilience */
#customCard > div:last-child {
  display: flex !important;
  flex-wrap: wrap;
  gap: 10px !important;
  align-items: center;
}
/* Stepper section */
#customCard > div:last-child > .custom-stepper {
  flex: 1 1 240px;
  min-width: 0;
}
/* Buttons container (Start/Reset) */
#customCard > div:last-child > div:last-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px !important;
  flex: 1 1 220px;
  min-width: 0;
  max-width: 100%;
}
/* Let buttons shrink without clipping their text */
#customCard > div:last-child > div:last-child .timer-button {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
}
/* Stack controls on narrow screens so buttons don't get clipped */
@media (max-width: 640px) {
  #customCard > div:last-child { grid-template-columns: 1fr !important; row-gap: 8px !important; }
  #customCard > div:last-child > div:last-child { justify-content: stretch !important; gap: 6px !important; }
  #customCard > div:last-child > div:last-child .timer-button { flex: 1 1 0; min-width: 0; }
}
