/* ===== THEME TOKENS ===== */
:root {
  --color-primary: #EC6426;
  --color-secondary: #F8A91F;
  --color-bg: #FDE3CF;
  --color-surface: #ffffff;
  --color-text: #632713;
  --color-card: #fff7f1;
  --color-border: rgba(99, 39, 19, 0.15);
  --color-muted: #8b5a4a;
  --shadow-sm: 0 1px 3px rgba(99, 39, 19, 0.08);
  --shadow-md: 0 4px 12px rgba(99, 39, 19, 0.1);
  --shadow-lg: 0 8px 24px rgba(99, 39, 19, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

[data-theme="dark"] {
  --color-bg: #2b140c;
  --color-surface: #3a1c10;
  --color-text: #ffe7d6;
  --color-card: #4a2415;
  --color-border: rgba(255, 231, 214, 0.15);
  --color-muted: #c4a898;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* ===== COMPONENT TOKENS ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

a {
  color: var(--color-primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: opacity 0.2s, transform 0.15s;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  opacity: 0.92;
}
.btn-secondary {
  background: var(--color-secondary);
  color: #632713;
}
.btn-secondary:hover {
  opacity: 0.92;
}
.btn-ghost {
  background: var(--color-card);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover {
  background: var(--color-surface);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--color-border);
  border-radius: 12px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle[aria-pressed="true"] {
  background: var(--color-primary);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--color-surface);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s;
}
.toggle[aria-pressed="true"]::after {
  transform: translateX(20px);
}

/* Cards */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.25rem;
  border: 1px solid var(--color-border);
}

/* Form controls */
label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--color-text);
}
input[type="text"],
input[type="number"],
input[type="time"],
select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
input:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(236, 98, 38, 0.2);
}

/* ===== LAYOUT ===== */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem 6rem;
  min-height: 100vh;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--color-text);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Dashboard */
.dashboard-section {
  padding: 1.25rem 0;
}
.dashboard-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--color-muted);
}
.dashboard-meta span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Rule cards grid */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.rule-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.rule-card-main {
  flex: 1;
  min-width: 0;
}
.rule-card-pair {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--color-text);
}
.rule-card-meta {
  font-size: 0.875rem;
  color: var(--color-muted);
  margin-top: 0.25rem;
}
.rule-card-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.rule-card-actions .btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--color-muted);
}
.rule-card-actions .btn-icon:hover {
  background: var(--color-surface);
  color: var(--color-primary);
}
.rule-card.disabled .rule-card-pair,
.rule-card.disabled .rule-card-meta {
  opacity: 0.65;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-muted);
}
.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.6;
}
.empty-state p {
  margin: 0 0 1rem;
  font-size: 1rem;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  z-index: 20;
  transition: transform 0.2s, box-shadow 0.2s;
}
.fab:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 28px rgba(236, 98, 38, 0.35);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}
.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}
.modal {
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}
.modal-close {
  padding: 0.5rem;
  color: var(--color-muted);
  border-radius: var(--radius-sm);
}
.modal-close:hover {
  background: var(--color-card);
  color: var(--color-text);
}
.modal-body {
  padding: 1.25rem;
}
.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
}

/* Form groups */
.form-group {
  margin-bottom: 1rem;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-group-day {
  display: none;
}
.form-group-day.visible {
  display: block;
}

/* Settings backdrop */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}
.settings-backdrop.is-visible {
  opacity: 1;
  visibility: visible;
}

/* Settings panel */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 360px;
  height: 100vh;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}
.settings-panel.is-open {
  transform: translateX(0);
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.settings-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}
.settings-body {
  padding: 1.25rem;
}
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.settings-item label {
  margin: 0;
  font-weight: 500;
}
.settings-export {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.5rem;
}
.settings-export .btn {
  width: 100%;
  justify-content: center;
}
.settings-meta {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.875rem;
  color: var(--color-muted);
}

/* ===== UTILITIES ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.hidden {
  display: none !important;
}
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }

/* Responsive */
@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  .rule-card {
    flex-direction: column;
    align-items: stretch;
  }
  .rule-card-actions {
    justify-content: space-between;
  }
}
