/* ==============================================================================
   BETTERGJK — MODERN KEPLER THEME & RESPONSIVE STYLES
   ============================================================================== */

:root {
  /* Color Palette - Light Mode Default */
  --bg-app: #F8F9FA;
  --bg-card: #ffffff;
  --bg-card-header: #FAFAFC;
  --bg-accent: #EBF3FF;
  --bg-hover: #F1F3F5;
  --bg-input: #FFFFFF;
  
  --text-main: #1A1D20;
  --text-muted: #6C757D;
  --text-inverse: #FFFFFF;

  --accent-primary: #1971C2;
  --accent-primary-hover: #1864AB;
  --accent-success: #2B8A3E;
  --accent-warning: #E67700;
  --accent-danger: #C92A2A;

  --border-color: rgba(0, 0, 0, 0.08);
  --border-color-hover: rgba(0, 0, 0, 0.16);

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.03), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0, 0, 0, 0.04);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

[data-theme="dark"] {
  --bg-app: #0F1216;
  --bg-card: #181C22;
  --bg-card-header: #1E232B;
  --bg-accent: #1C2B3E;
  --bg-hover: #262D38;
  --bg-input: #15191E;

  --text-main: #F1F3F5;
  --text-muted: #909BA6;
  --text-inverse: #0F1216;

  --accent-primary: #339AF0;
  --accent-primary-hover: #4DABF7;
  --accent-success: #40C057;
  --accent-warning: #FCC419;
  --accent-danger: #FF6B6B;

  --border-color: rgba(255, 255, 255, 0.09);
  --border-color-hover: rgba(255, 255, 255, 0.18);

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* ==============================================================================
   HEADER
   ============================================================================== */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  transition: transform 0.5s ease;
}

.header-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.brand-logo {
  text-decoration: none;
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.logo-short {
  display: none;
}

.logo-short span:first-child {
  letter-spacing: -0.5px;
}

.logo-kepler {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--text-main);
}

.logo-sub {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: var(--accent-primary);
  text-transform: uppercase;
}

.class-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-accent);
  color: var(--accent-primary);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
}

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

/* ==============================================================================
   BUTTONS & CONTROLS
   ============================================================================== */
.btn-primary {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent-primary);
  color: var(--text-inverse);
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

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

.btn-primary:active {
  transform: scale(0.97);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card-header);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  color: var(--accent-primary);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-ghost:hover {
  background: var(--bg-accent);
  border-color: var(--accent-primary);
}

.btn-reorder {
  display: none;
}

.btn-selected {
  background-color: var(--accent-primary);
  color: var(--bg-card);
}

.order-control {
  transition: all 0.5s ease-in-out;
}

/* Theme Toggle icons */
[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; }

/* Pill Group Selectors */
.pill-group {
  display: inline-flex;
  background: var(--bg-hover);
  padding: 3px;
  border-radius: var(--radius-full);
  gap: 2px;
  border: 1px solid var(--border-color);
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pill:hover {
  color: var(--text-main);
}

.pill.active {
  background: var(--bg-card);
  color: var(--accent-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ==============================================================================
   DASHBOARD GRID & CARDS (3-ITEM LAYOUT)
   ============================================================================== */
.app-main {
  flex: 1;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
}

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.dashboard-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition-normal), transform var(--transition-fast), border-color var(--transition-fast);
}

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

/* Drag & Drop Visual States */
.dashboard-card.dragging {
  opacity: 0.45;
  transform: scale(0.98);
  border: 2px dashed var(--accent-primary);
}

.dashboard-card.drag-over {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-primary);
  transform: translateY(2px);
}

.card-header {
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: all 0.5s ease;
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.drag-handle:hover {
  color: var(--accent-primary);
  background: var(--bg-hover);
}

.drag-handle:active {
  cursor: grabbing;
}

.card-title-icon {
  font-size: 1.25rem;
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.card-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.order-buttons {
  display: inline-flex;
  gap: 2px;
  background: var(--bg-hover);
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.btn-arrow {
  border: none;
  background: transparent;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-arrow:hover {
  background: var(--bg-card);
  color: var(--accent-primary);
}

.card-content {
  padding: 1.25rem;
  min-height: 180px;
}

/* ==============================================================================
   ITEM 1: TIMETABLE IFRAME
   ============================================================================== */
.card-iframe-wrapper {
  padding: 0;
  position: relative;
  height: 700px;
  background: #FFFFFF;
}

#card-timetable {
  height: 800px;
}

#timetableFrame {
  width: 100%;
  height: 700px;
  border: none;
  display: block;
}

.iframe-loader {
  position: absolute;
  inset: 0;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
  z-index: 5;
}

.iframe-loader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ==============================================================================
   ITEM 2: SUBSTITUTIONS
   ============================================================================== */
.substitutions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-box {
  background: var(--bg-card-header);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.stat-icon {
  font-size: 1.4rem;
  background: var(--bg-card);
  padding: 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.stat-details h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-details p {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Substitutions Table */
.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.subs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

.subs-table th {
  background: var(--bg-card-header);
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.subs-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.subs-table tr:last-child td {
  border-bottom: none;
}

.subs-table tr:hover {
  background: var(--bg-hover);
}

.subs-table tr.highlighted {
  background: var(--bg-accent);
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

/* ==============================================================================
   ITEM 3: CANTEEN (TODAY'S PART & WEEK MENU)
   ============================================================================== */
.canteen-today-hero {
  background: linear-gradient(135deg, var(--bg-card-header), var(--bg-card));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.today-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.today-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.today-date-badge {
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-accent);
  color: var(--accent-primary);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
}

.meals-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.meal-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--bg-card);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.meal-row:hover {
  border-color: var(--border-color-hover);
  transform: translateX(3px);
}

.meal-tag {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--bg-hover);
  color: var(--text-main);
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
}

.meal-tag.soup {
  background: #FFF3BF;
  color: #D9480F;
}

[data-theme="dark"] .meal-tag.soup {
  background: #5C3A00;
  color: #FCC419;
}

.meal-desc {
  font-size: 0.925rem;
  color: var(--text-main);
  flex: 1;
}

/* Allergens link footer */
.canteen-footer {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 0.8rem;
}

/* ==============================================================================
   LOADING & SPINNERS
   ============================================================================== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  gap: 0.75rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ==============================================================================
   MODAL / SETTINGS DIALOG
   ============================================================================== */
.modal-dialog {
  border: none;
  background: transparent;
  width: 100vw;
  height: 100vh;
  max-width: 100%;
  max-height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-dialog[open] {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  animation: modal-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.modal-title h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  line-height: 1;
}

.btn-close:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.setting-info label {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-main);
}

.setting-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.custom-select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.925rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.custom-select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--bg-accent);
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

.bottom-screen {
  width: 100%;
  justify-content: center;
  position: fixed;
  bottom: 0%;
  left: 0%;
  z-index: 1;
  border: none;
  transition: all 0.5s ease;
  transform: translateY(100%);
}

.bottom-screen button {
  box-shadow: var(--shadow-lg);
}

footer {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20pt;
}

/* ==============================================================================
   RESPONSIVE QUERIES
   ============================================================================== */
@media (max-width: 768px) {
  .header-inner {
    padding: 0.6rem 1rem;
  }

  .brand-group {
    gap: 0.8rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .card-controls {
    width: 100%;
    justify-content: space-between;
  }

  .card-iframe-wrapper {
    height: 480px;
  }

  .order-control {
    /* display: none; */
    opacity: 0;
    transform: scale(0);
    padding: 0;
    width: 0;
  }

  .btn-reorder {
    display: block;
  }
}

@media (max-width: 550px) {
  #btnOpenSettings span{
    display: none;
  }
}

@media (max-width: 450px) {

  .logo-long {
    display: none;
  }

  .logo-short{
    display: flex;
  }
}

@media (max-width: 360px) {
  .brand-group {
    gap: 0.2rem;
  }
}

@media (max-width: 355px) {
  .brand-logo {
    display: none;
  }
}