/* =========================================================
   VARIABLES & THEMING
   ========================================================= */
:root {
  --font-base: 'Inter', 'Padauk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;

  /* Dark Theme (Default) */
  --bg-app: #0b0f17;
  --bg-card: #151c28;
  --bg-card-subtle: #1c2536;
  --border: #232f42;
  --border-light: #2e3c54;

  --text-main: #f1f5f9;
  --text-sub: #94a3b8;
  --text-muted: #64748b;

  --on-green: #10b981;
  --on-green-bg: rgba(16, 185, 129, 0.15);
  --on-green-border: rgba(16, 185, 129, 0.35);

  --off-red: #ef4444;
  --off-red-bg: rgba(239, 68, 68, 0.14);
  --off-red-border: rgba(239, 68, 68, 0.35);

  --primary-blue: #38bdf8;
  --primary-blue-hover: #0284c7;

  /* Group Colors */
  --group-a: #eab308;
  --group-b: #22c55e;
  --group-c: #06b6d4;
  --group-d: #f43f5e;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

[data-theme="light"] {
  --bg-app: #f4f6fa;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-light: #cbd5e1;

  --text-main: #0f172a;
  --text-sub: #475569;
  --text-muted: #94a3b8;

  --on-green: #059669;
  --on-green-bg: #ecfdf5;
  --on-green-border: #a7f3d0;

  --off-red: #dc2626;
  --off-red-bg: #fef2f2;
  --off-red-border: #fecaca;

  --primary-blue: #0284c7;
  --primary-blue-hover: #0369a1;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* =========================================================
   BASE & RESET
   ========================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-base);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app-shell {
  width: 100%;
  max-width: 520px; /* Optimal mobile viewport containment */
  min-height: 100vh;
  background-color: var(--bg-app);
  display: flex;
  flex-direction: column;
  padding: 0 1rem 2rem;
}

/* =========================================================
   HEADER
   ========================================================= */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background-color: var(--bg-app);
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.6rem;
  background: var(--bg-card-subtle);
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-sub);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-sub);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  color: var(--text-main);
  border-color: var(--border-light);
}

.icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="light"] .moon-icon { display: block; }

/* =========================================================
   CARDS & COMMON UTILS
   ========================================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.field-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 0.6rem;
}

.custom-select-wrapper {
  position: relative;
}

.form-select {
  width: 100%;
  appearance: none;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.form-select:focus {
  border-color: var(--primary-blue);
}

.group-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border);
}

.group-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border);
}

.group-letter {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  background-color: var(--group-a);
}

.group-title {
  font-size: 0.88rem;
  font-weight: 600;
}

.quota-tag {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-sub);
}

/* =========================================================
   7 DAYS HORIZONTAL STRIP
   ========================================================= */
.days-nav-section {
  margin-bottom: 1.25rem;
}

.section-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
}

.section-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-sub);
}

.btn-text {
  background: none;
  border: none;
  color: var(--primary-blue);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.days-scroll-container {
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.days-scroll-container::-webkit-scrollbar {
  height: 4px;
}
.days-scroll-container::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

.day-card {
  flex: 0 0 calc(25% - 0.5rem);
  min-width: 82px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  text-align: center;
  cursor: pointer;
  scroll-snap-align: start;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.day-card:hover {
  border-color: var(--border-light);
}

.day-card.active {
  background: var(--bg-card-subtle);
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 1px var(--primary-blue);
}

.day-rel-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.day-card.is-today .day-rel-name {
  color: var(--primary-blue);
  font-weight: 700;
}

.day-date-number {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.day-cycle-label {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-sub);
  background: var(--bg-app);
  border-radius: 4px;
  padding: 0.1rem 0.25rem;
}

/* =========================================================
   LIVE STATUS HERO CARD
   ========================================================= */
.status-hero-card {
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  margin-bottom: 1.25rem;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.status-hero-card.status-on {
  background: linear-gradient(145deg, var(--on-green-bg), var(--bg-card));
  border-color: var(--on-green-border);
}

.status-hero-card.status-off {
  background: linear-gradient(145deg, var(--off-red-bg), var(--bg-card));
  border-color: var(--off-red-border);
}

.status-hero-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.live-dot-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.live-pulse {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background-color: var(--on-green);
  box-shadow: 0 0 10px var(--on-green);
  animation: pulse-ring 1.8s infinite;
}

.status-hero-card.status-off .live-pulse {
  background-color: var(--off-red);
  box-shadow: 0 0 10px var(--off-red);
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.status-state-text {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cycle-day-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border);
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
}

.status-hero-body {
  display: flex;
  align-items: center;
  gap: 1.15rem;
  margin-bottom: 1.35rem;
}

.status-icon-box {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.status-hero-card.status-on .status-icon-box {
  border-color: var(--on-green-border);
  color: var(--on-green);
}

.status-hero-card.status-off .status-icon-box {
  border-color: var(--off-red-border);
  color: var(--off-red);
}

.status-headline {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.3;
}

.status-subline {
  font-size: 0.88rem;
  color: var(--text-sub);
  margin-top: 0.25rem;
}

.hero-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

[data-theme="light"] .hero-stats-grid {
  background: rgba(255, 255, 255, 0.7);
}

.hero-stat-item {
  display: flex;
  flex-direction: column;
  text-align: center;
  gap: 0.15rem;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 700;
}

.text-accent {
  color: var(--primary-blue);
}

/* =========================================================
   24-HOUR BAR & SLOTS
   ========================================================= */
.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-heading {
  font-size: 0.95rem;
  font-weight: 700;
}

.clock-display {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-card-subtle);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.hourly-bar-container {
  margin-bottom: 1.25rem;
}

.hourly-bar {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  background: var(--bg-app);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
  height: 38px;
}

.hour-block {
  border-radius: 3px;
  position: relative;
  transition: opacity 0.15s ease;
  cursor: pointer;
}

.hour-block.is-on {
  background-color: var(--on-green);
}

.hour-block.is-off {
  background-color: var(--bg-card-subtle);
}

.hour-block.current-now {
  box-shadow: 0 0 0 2px #fff, 0 0 8px rgba(255, 255, 255, 0.8);
  z-index: 2;
}

.bar-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.subheading {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.slots-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.slot-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.slot-item.slot-on {
  background: var(--on-green-bg);
  color: var(--on-green);
  border: 1px solid var(--on-green-border);
}

.slot-item.slot-off {
  background: var(--bg-card-subtle);
  color: var(--text-sub);
  border: 1px solid var(--border);
}

.slot-time {
  font-family: var(--font-mono);
  font-weight: 700;
}

.slot-duration {
  font-size: 0.78rem;
}

.mt-3 {
  margin-top: 1rem;
}

/* =========================================================
   TABLE ACCORDION
   ========================================================= */
.accordion-trigger {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.accordion-trigger .chevron {
  transition: transform 0.2s ease;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.accordion-trigger.expanded .chevron {
  transform: rotate(180deg);
}

.accordion-content {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  text-align: center;
}

.schedule-table th, .schedule-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.25rem;
}

.schedule-table th {
  background: var(--bg-card-subtle);
  font-family: var(--font-mono);
  color: var(--text-sub);
}

.cell-all { background: rgba(148, 163, 184, 0.2); }
.cell-a { background: rgba(234, 179, 8, 0.35); font-weight: 700; }
.cell-b { background: rgba(34, 197, 94, 0.35); font-weight: 700; }
.cell-c { background: rgba(6, 182, 212, 0.35); font-weight: 700; }
.cell-d { background: rgba(244, 63, 94, 0.35); font-weight: 700; }
.cell-ad { background: rgba(234, 179, 8, 0.2); }
.cell-ba { background: rgba(34, 197, 94, 0.2); }
.cell-bc { background: rgba(6, 182, 212, 0.2); }
.cell-cd { background: rgba(244, 63, 94, 0.2); }
.cell-cb { background: rgba(6, 182, 212, 0.2); }
.cell-da { background: rgba(244, 63, 94, 0.2); }
.cell-dc { background: rgba(244, 63, 94, 0.2); }
.cell-ab { background: rgba(234, 179, 8, 0.2); }

.table-note {
  font-size: 0.78rem;
  color: var(--text-sub);
  line-height: 1.5;
}

/* =========================================================
   FOOTER
   ========================================================= */
.app-footer {
  text-align: center;
  padding: 1.5rem 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.app-footer .sub-text {
  font-size: 0.72rem;
  margin-top: 0.25rem;
}

/* =========================================================
   SETTINGS MODAL
   ========================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-instruction {
  font-size: 0.82rem;
  color: var(--text-sub);
  margin-bottom: 1.25rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 0.4rem;
}

.form-input {
  width: 100%;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.btn {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-align: center;
}

.btn-primary {
  background: var(--primary-blue);
  color: #0b0f17;
}

.btn-primary:hover {
  background: var(--primary-blue-hover);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-sub);
}

.btn-outline:hover {
  color: var(--text-main);
  border-color: var(--border-light);
}

.full-width {
  width: 100%;
}
