/* ==========================================================================
   GuestyAgent Concierge — Elevated Theme (2025)
   ========================================================================== */

/* === ANIMATABLE CUSTOM PROPERTIES === */
@property --coral-l   { syntax: '<percentage>'; inherits: false; initial-value: 62%; }
@property --shadow-y  { syntax: '<length>';      inherits: false; initial-value: 2px; }

/* === CASCADE LAYERS === */
@layer reset, tokens, base, layout, components, states, utilities;

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

/* ---------- Tokens ---------- */
@layer tokens {
  :root {
    /* Brand — OKLCH for perceptual uniformity */
    --coral:        oklch(62% 0.22 24);
    --coral-hover:  oklch(55% 0.22 24);
    --coral-light:  oklch(97.5% 0.03 24);
    --coral-glow:   oklch(62% 0.22 24 / 0.25);

    /* Neutrals */
    --dark:          oklch(30% 0.008 260);
    --gray:          oklch(53% 0.008 260);
    --mid-gray:      oklch(70% 0.005 260);
    --light-gray:    oklch(91% 0.004 260);
    --lighter-gray:  oklch(96.5% 0.003 260);
    --bg:            oklch(100% 0 0);
    --bg-warm:       oklch(99% 0.008 60);

    /* Semantic */
    --success:        oklch(52% 0.165 145);
    --success-light:  oklch(96% 0.035 145);
    --success-glow:   oklch(52% 0.165 145 / 0.20);
    --warning:        oklch(48% 0.175 30);
    --amber:          oklch(72% 0.155 72);
    --amber-light:    oklch(97% 0.04 72);
    --amber-glow:     oklch(72% 0.155 72 / 0.20);

    /* Typography */
    --font: 'Nunito Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Geometry */
    --radius:    14px;
    --radius-sm:  9px;
    --radius-xs:  6px;

    /* Layered shadows */
    --shadow-sm:    0 1px 2px oklch(0% 0 0 / 0.05), 0 1px 4px oklch(0% 0 0 / 0.04);
    --shadow:       0 2px 8px oklch(0% 0 0 / 0.07), 0 1px 3px oklch(0% 0 0 / 0.04);
    --shadow-md:    0 6px 20px oklch(0% 0 0 / 0.09), 0 2px 6px oklch(0% 0 0 / 0.05);
    --shadow-hover: 0 10px 30px oklch(0% 0 0 / 0.11), 0 3px 8px oklch(0% 0 0 / 0.06);
    --shadow-modal: 0 24px 64px oklch(0% 0 0 / 0.22), 0 8px 24px oklch(0% 0 0 / 0.10);

    /* Easing */
    --ease-spring: cubic-bezier(0.34, 1.2, 0.64, 1);
    --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  }
}

/* ---------- Base ---------- */
@layer base {
  body {
    font-family: var(--font);
    color: var(--dark);
    background: var(--bg-warm);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }

  :focus-visible {
    outline: 2px solid var(--coral);
    outline-offset: 3px;
    border-radius: var(--radius-xs);
  }
}

/* ---------- Layout ---------- */
@layer layout {

  /* Top Bar */
  .topbar {
    background: oklch(100% 0 0 / 0.88);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--light-gray);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .topbar-inner {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
  }

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

  .brand-icon {
    width: 26px;
    height: 26px;
    color: var(--coral);
  }

  .brand-text {
    font-size: 20px;
    font-weight: 900;
    color: var(--coral);
    letter-spacing: -0.5px;
  }

  .topbar-subtitle {
    color: var(--mid-gray);
    font-size: 13px;
    font-weight: 600;
    padding-left: 16px;
    border-left: 1px solid var(--light-gray);
  }

  .topbar-signout {
    margin-left: auto;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    transition: color 120ms, background 120ms;
  }

  .topbar-signout:hover {
    color: var(--dark);
    background: var(--lighter-gray);
  }

  .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 24px;
  }
}

/* ---------- Components ---------- */
@layer components {

  /* Greeting */
  .greeting {
    font-size: 22px;
    font-weight: 800;
    color: var(--dark);
    margin-bottom: 24px;
    letter-spacing: -0.4px;
    text-wrap: balance;
  }

  /* Stats Row */
  .stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
    gap: 14px;
    margin-bottom: 24px;
  }

  .stat-card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--light-gray);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: box-shadow 200ms var(--ease-out), transform 200ms var(--ease-out);
  }

  .stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
  }

  .stat-card--ready {
    border-left: 3px solid var(--success);
    background: linear-gradient(140deg, var(--bg) 0%, var(--success-light) 130%);
  }

  .stat-card--pending {
    border-left: 3px solid var(--amber);
    background: linear-gradient(140deg, var(--bg) 0%, var(--amber-light) 130%);
  }

  .stat-card--action {
    border-left: none;
    justify-content: center;
    align-items: center;
    background: var(--lighter-gray);
  }

  .stat-number {
    font-size: 36px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -1.5px;
  }

  .stat-card--ready .stat-number  { color: var(--success); }
  .stat-card--pending .stat-number { color: var(--amber); }

  .stat-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    margin-top: 2px;
  }

  .stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    flex-shrink: 0;
  }

  .stat-card--ready .stat-icon   { background: var(--success-light); color: var(--success); }
  .stat-card--pending .stat-icon { background: var(--amber-light);   color: var(--amber); }

  .automation-label {
    font-size: 10px;
    font-weight: 800;
    color: var(--mid-gray);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
  }

  /* Cards */
  .card {
    background: var(--bg);
    border: 1px solid var(--light-gray);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
    overflow: hidden;
  }

  .card--muted {
    background: var(--lighter-gray);
    box-shadow: none;
  }

  .card-header {
    padding: 14px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--light-gray);
  }

  .card-header--collapsible {
    cursor: pointer;
    user-select: none;
    transition: background 120ms;
  }

  .card-header--collapsible:hover {
    background: oklch(0% 0 0 / 0.02);
  }

  .card-title {
    font-size: 15px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.2px;
  }

  .card-actions {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  /* Collapsibles — CSS grid animation, no JS display toggling */
  .collapsible {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 320ms var(--ease-out);
    overflow: hidden;
  }

  .collapsible.open {
    grid-template-rows: 1fr;
  }

  .collapsible-inner {
    min-height: 0;
    overflow: hidden;
  }

  .collapse-chevron {
    transition: transform 220ms var(--ease-out);
    color: var(--mid-gray);
    flex-shrink: 0;
  }

  .collapse-chevron.open {
    transform: rotate(180deg);
  }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 120ms var(--ease-out);
    letter-spacing: 0.1px;
    white-space: nowrap;
  }

  .btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    pointer-events: none;
  }

  .btn--primary {
    background: var(--coral);
    color: #fff;
    box-shadow: 0 2px 10px var(--coral-glow);
  }

  .btn--primary:hover:not(:disabled) {
    background: var(--coral-hover);
    box-shadow: 0 5px 18px var(--coral-glow);
    transform: translateY(-1px);
  }

  .btn--primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 4px var(--coral-glow);
  }

  .btn--outline {
    background: var(--bg);
    color: var(--dark);
    border: 1.5px solid var(--light-gray);
  }

  .btn--outline:hover:not(:disabled) {
    border-color: oklch(78% 0.006 260);
    background: var(--lighter-gray);
  }

  .btn--test {
    background: transparent;
    color: var(--gray);
    border: 1.5px solid var(--light-gray);
    padding: 5px 11px;
    font-size: 12px;
    border-radius: var(--radius-xs);
  }

  .btn--test:hover:not(:disabled) {
    border-color: var(--coral);
    color: var(--coral);
    background: var(--coral-light);
  }

  .btn--test-done {
    border-color: var(--success)      !important;
    color:        var(--success)      !important;
    background:   var(--success-light) !important;
  }

  .btn--reminder {
    background: transparent;
    color: var(--amber);
    border: 1.5px solid color-mix(in oklch, var(--amber) 45%, transparent);
    padding: 5px 11px;
    font-size: 12px;
    border-radius: var(--radius-xs);
  }

  .btn--reminder:hover:not(:disabled) {
    background: var(--amber-light);
    border-color: var(--amber);
  }

  .btn--reminder-done {
    border-color: var(--success)      !important;
    color:        var(--success)      !important;
    background:   var(--success-light) !important;
  }

  .btn--download {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font);
    color: var(--coral);
    border: 1.5px solid color-mix(in oklch, var(--coral) 38%, transparent);
    text-decoration: none;
    transition: all 120ms;
    background: var(--coral-light);
  }

  .btn--download:hover {
    background: var(--coral);
    color: #fff;
    border-color: var(--coral);
  }

  /* History hint */
  .history-hint {
    padding: 10px 22px 14px;
    font-size: 13px;
    color: var(--mid-gray);
    line-height: 1.5;
  }

  .history-error {
    padding: 8px 22px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--warning);
  }

  /* Table */
  .reservations-table {
    width: 100%;
    border-collapse: collapse;
  }

  .reservations-table th {
    text-align: left;
    padding: 9px 16px;
    font-size: 11px;
    font-weight: 800;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    background: var(--lighter-gray);
    border-bottom: 1px solid var(--light-gray);
  }

  .reservations-table td {
    padding: 11px 16px;
    font-size: 13.5px;
    border-bottom: 1px solid var(--light-gray);
    vertical-align: middle;
  }

  .reservations-table tbody tr {
    transition: background 100ms;
  }

  .reservations-table tbody tr:hover {
    background: var(--bg-warm);
  }

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

  .col-check { width: 40px; }

  .reservations-table input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--coral);
    cursor: pointer;
  }

  /* Badges */
  .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 800;
  }

  .badge--amber {
    background: var(--amber-light);
    color: var(--amber);
    border: 1px solid color-mix(in oklch, var(--amber) 22%, transparent);
  }

  .badge--green {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid color-mix(in oklch, var(--success) 22%, transparent);
  }

  .missing-pill {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    background: var(--coral-light);
    color: var(--coral);
    margin-right: 3px;
    border: 1px solid color-mix(in oklch, var(--coral) 22%, transparent);
  }

  /* Select All */
  .select-all-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray);
    cursor: pointer;
    transition: color 120ms;
  }

  .select-all-label:hover { color: var(--dark); }

  /* Empty State */
  .empty-state {
    padding: 48px 24px;
    text-align: center;
  }

  .empty-icon {
    margin-bottom: 14px;
    color: var(--success);
    opacity: 0.9;
  }

  .empty-state p {
    font-size: 14px;
    font-weight: 600;
    color: var(--mid-gray);
  }

  /* Calibration */
  .calibration-content { padding: 20px 22px; }

  .calibration-hint {
    font-size: 13px;
    color: var(--gray);
    margin-bottom: 20px;
    line-height: 1.6;
  }

  .calibration-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
  }

  .cal-field {
    background: var(--lighter-gray);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    border: 1px solid var(--light-gray);
  }

  .cal-label {
    display: block;
    font-size: 11px;
    font-weight: 800;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 8px;
  }

  .cal-inputs { display: flex; gap: 10px; }

  .cal-input-group {
    display: flex;
    align-items: center;
    flex: 1;
    background: var(--bg);
    border: 1.5px solid var(--light-gray);
    border-radius: var(--radius-xs);
    overflow: hidden;
    transition: border-color 120ms;
  }

  .cal-input-group:focus-within { border-color: var(--coral); }

  .cal-input-prefix {
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 800;
    color: var(--gray);
    background: var(--lighter-gray);
    border-right: 1px solid var(--light-gray);
  }

  .cal-input {
    border: none;
    outline: none;
    padding: 6px 8px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    width: 100%;
    color: var(--dark);
    background: transparent;
  }

  .cal-input::-webkit-inner-spin-button { opacity: 0.3; }

  .calibration-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
  }

  .calibration-status {
    font-size: 13px;
    font-weight: 600;
    min-height: 20px;
  }

  .cal-status--success { color: var(--success); }
  .cal-status--error   { color: var(--warning); }

  /* Modal */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: oklch(0% 0 0 / 0.40);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }

  .modal {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    border: 1px solid var(--light-gray);
    width: 560px;
    max-width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modal-in 340ms var(--ease-spring) forwards;
  }

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

  @starting-style {
    .modal { opacity: 0; transform: scale(0.93) translateY(14px); }
  }

  .modal-header {
    padding: 20px 22px 18px;
    border-bottom: 1px solid var(--light-gray);
  }

  .modal-header h2 {
    font-size: 17px;
    font-weight: 900;
    letter-spacing: -0.3px;
  }

  .modal-progress-text {
    font-size: 13px;
    color: var(--gray);
    margin-top: 4px;
  }

  .modal-body {
    padding: 16px 22px;
    overflow-y: auto;
    flex: 1;
  }

  .modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--light-gray);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--lighter-gray);
    border-radius: 0 0 var(--radius) var(--radius);
  }

  .modal-summary {
    font-size: 13px;
    font-weight: 700;
  }

  /* Log entries */
  .log-entry {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--lighter-gray);
    animation: log-in 180ms var(--ease-out) both;
  }

  @keyframes log-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
  }

  .log-entry:last-child { border-bottom: none; }

  .log-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .log-entry--info .log-icon    { color: var(--mid-gray); }
  .log-entry--success .log-icon { color: var(--success); }
  .log-entry--error .log-icon   { color: var(--warning); }

  .log-text { flex: 1; line-height: 1.45; }

  /* Loading Overlay */
  .loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-warm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 300;
    transition: opacity 0.4s var(--ease-out);
  }

  .loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .spinner {
    width: 32px;
    height: 32px;
    border: 2.5px solid var(--light-gray);
    border-top-color: var(--coral);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
  }

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

  .loading-overlay p {
    font-size: 14px;
    font-weight: 700;
    color: var(--mid-gray);
  }
}

/* ---------- States ---------- */
@layer states {
  .btn--automation-on {
    background: var(--success-light)                                             !important;
    color:      var(--success)                                                   !important;
    border:     1.5px solid color-mix(in oklch, var(--success) 30%, transparent) !important;
    box-shadow: 0 2px 8px var(--success-glow)                                   !important;
  }

  .btn--automation-off {
    background: var(--coral-light)                                              !important;
    color:      var(--coral)                                                    !important;
    border:     1.5px solid color-mix(in oklch, var(--coral) 30%, transparent)  !important;
  }
}

/* ---------- Utilities & Responsive ---------- */
@layer utilities {
  @media (max-width: 900px) {
    .stats-row { grid-template-columns: 1fr 1fr; }
  }

  @media (max-width: 768px) {
    .stats-row { grid-template-columns: 1fr; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .card-actions { width: 100%; justify-content: space-between; }
    .reservations-table { font-size: 12px; }
    .reservations-table th, .reservations-table td { padding: 8px 10px; }
    .topbar-subtitle { display: none; }
    .container { padding: 16px; }
  }

  /* Scroll-driven reveal */
  @supports (animation-timeline: view()) {
    .card {
      animation: card-reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 18%;
    }

    @keyframes card-reveal {
      from { opacity: 0.5; transform: translateY(10px); }
      to   { opacity: 1;   transform: translateY(0); }
    }
  }
}
