/* Sumni Hotel Manager — modern light/dark UI, mobile-first, PC-perfect. */

:root {
  --accent: #2563eb;
  --accent2: #7c3aed;
  --gradient: linear-gradient(135deg, #2563eb, #7c3aed);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.05);
  --shadow-pop: 0 6px 18px rgba(15, 23, 42, 0.10), 0 24px 60px rgba(15, 23, 42, 0.16);
  --fast: 0.16s ease;
}

html[data-theme="light"] {
  --bg: #f3f4f8;
  --bg-grad: radial-gradient(80% 50% at 15% 0%, rgba(37, 99, 235, 0.08), transparent 60%),
    radial-gradient(60% 40% at 90% 10%, rgba(124, 58, 237, 0.07), transparent 60%);
  --card: #ffffff;
  --inset: #f0f2f7;
  --text: #0f172a;
  --secondary: #5b6472;
  --tertiary: #9aa3b3;
  --hairline: rgba(15, 23, 42, 0.08);
  --strong-line: rgba(15, 23, 42, 0.14);
  --tint-bg: rgba(37, 99, 235, 0.10);
  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.12);
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.10);
  --amber: #d97706;
  --amber-bg: rgba(217, 119, 6, 0.13);
  --glass: rgba(255, 255, 255, 0.78);
  --ctrl: rgba(120, 128, 145, 0.14);
}

html[data-theme="dark"] {
  --bg: #0b1020;
  --bg-grad: radial-gradient(80% 50% at 15% 0%, rgba(37, 99, 235, 0.14), transparent 60%),
    radial-gradient(60% 40% at 90% 10%, rgba(124, 58, 237, 0.12), transparent 60%);
  --card: #151b2e;
  --inset: #10162a;
  --text: #eef1f8;
  --secondary: #9aa5bd;
  --tertiary: #5f6b84;
  --hairline: rgba(255, 255, 255, 0.07);
  --strong-line: rgba(255, 255, 255, 0.14);
  --tint-bg: rgba(96, 165, 250, 0.14);
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --amber: #fbbf24;
  --amber-bg: rgba(251, 191, 36, 0.12);
  --glass: rgba(21, 27, 46, 0.78);
  --ctrl: rgba(160, 174, 205, 0.14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { background: var(--bg); -webkit-text-size-adjust: 100%; color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.3s ease, color 0.3s ease;
}

.hidden { display: none !important; }
.rb-mono, .num, .stats .num { font-variant-numeric: tabular-nums; }

button { font-family: var(--font); cursor: pointer; }
input { font-family: var(--font); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.icon-btn.loading svg { animation: spin 0.9s linear infinite; }
.icon-btn:disabled { opacity: 0.6; cursor: default; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= BUTTONS ================= */

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--ctrl);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--fast), transform 0.12s ease, opacity var(--fast), box-shadow var(--fast);
}
.btn:active { transform: scale(0.97); }
.btn-accent { background: var(--gradient); color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28); }
.btn-accent:hover { box-shadow: 0 6px 20px rgba(37, 99, 235, 0.36); }
.btn-block { width: 100%; padding: 13px 16px; border-radius: 14px; font-size: 16px; }

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--secondary);
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  flex-shrink: 0;
  transition: background var(--fast), color var(--fast), transform 0.12s ease;
}
.icon-btn:hover { background: var(--ctrl); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn-float {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 18px);
  right: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--secondary);
}

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

.btn-link {
  appearance: none;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 0 2px;
  text-decoration: none;
  transition: opacity var(--fast);
}
.btn-link:hover { opacity: 0.75; }

/* ================= LOGIN ================= */

.login-view {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  overflow-y: auto;
  z-index: 5;
}
.login-bg {
  position: absolute;
  inset: 0;
  background-image: var(--bg-grad);
  pointer-events: none;
}
.login-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow-pop);
  padding: 36px 30px 28px;
  text-align: center;
  animation: rise 0.35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.brand-logo {
  display: inline-block;
  line-height: 0;
}
.brand-logo .logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.brand-logo .logo-fallback { display: none; align-items: center; justify-content: center; font-weight: 800; letter-spacing: -0.02em; background: var(--gradient); color: #fff; border-radius: 14px; }
.brand-logo img.broken { display: none; }
.brand-logo img.broken + .logo-fallback { display: flex; }
.brand-logo-lg { width: 104px; height: 104px; margin: 0 auto 14px; }
.brand-logo-lg .logo-fallback { font-size: 52px; width: 100%; height: 100%; }
.brand-logo-lg svg { width: 54px; height: 54px; }

.login-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 4px; }
.login-sub { font-size: 14px; color: var(--secondary); margin: 0 0 26px; }

.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--secondary); }
.field input {
  appearance: none;
  width: 100%;
  border: 1px solid var(--strong-line);
  background: var(--inset);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  transition: border-color var(--fast), box-shadow var(--fast), background var(--fast);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
  background: var(--card);
}
.login-error {
  color: var(--red);
  background: var(--red-bg);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  margin-top: 16px;
  display: none;
}
.login-brand {
  margin-top: 24px;
  font-size: 13px;
  color: var(--tertiary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-brand b { color: var(--secondary); }

/* ================= TOP BAR ================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(1.8) blur(18px);
  backdrop-filter: saturate(1.8) blur(18px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand .brand-logo { width: 42px; height: 42px; flex-shrink: 0; }
.brand .brand-logo .logo-fallback { font-size: 22px; width: 100%; height: 100%; }
.brand-text { min-width: 0; }
.brand-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  white-space: nowrap;
}
.brand-sub { font-size: 12.5px; color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Search */
.search-wrap {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ctrl);
  border-radius: 12px;
  padding: 0 12px;
  min-width: 140px;
  order: 2;
  flex-basis: 100%;
}
.search-icon { color: var(--tertiary); flex-shrink: 0; }
.search-input {
  appearance: none;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font-size: 16px;
  width: 100%;
  padding: 11px 0;
}
.search-input::placeholder { color: var(--tertiary); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-wrap:focus-within { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16); }

/* Nav actions + dropdowns */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  order: 1;
  margin-left: auto;
}
.drop { position: relative; }
.drop-btn { border-radius: 12px; }
.drop-btn .chev { transition: transform var(--fast); }
.drop.open .drop-btn .chev { transform: rotate(180deg); }
.drop-badge {
  background: var(--gradient);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  line-height: 1;
}
.drop-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 280px;
  max-width: min(92vw, 340px);
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  box-shadow: var(--shadow-pop);
  padding: 8px;
  z-index: 40;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity var(--fast), transform var(--fast);
}
.drop.open .drop-panel { opacity: 1; transform: none; pointer-events: auto; }
.drop-panel-sm { min-width: 230px; }

/* Filter panel — centered on screen, always opens downward and scrolls vertically
   so the large number of options never spill off-screen (left/right) or overlap upward. */
.drop[data-drop="filters"] .drop-panel {
  position: fixed;
  left: 50%;
  right: auto;
  top: calc(env(safe-area-inset-top, 0px) + 96px);
  transform: translateX(-50%) translateY(-6px);
  width: min(92vw, 340px);
  max-width: none;
  max-height: min(68vh, calc(100vh - 130px));
  display: flex;
  flex-direction: column;
  padding: 8px;
}
.drop[data-drop="filters"].open .drop-panel { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.drop[data-drop="filters"] .drop-panel .drop-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--tertiary) transparent;
  padding: 2px;
  margin-right: -2px;
}
.drop[data-drop="filters"] .drop-panel .drop-scroll .drop-group { padding: 8px 10px; }
.drop[data-drop="filters"] .drop-panel .drop-actions {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 8px 4px;
  border-top: 1px solid var(--hairline);
  margin-top: 4px;
}

.drop-group { padding: 8px 10px; }
.drop-group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tertiary);
  margin: 0 2px 6px;
}
.drop-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--fast);
}
.drop-label:hover { background: var(--inset); }
.drop-label input {
  width: 19px;
  height: 19px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.drop-label.checked { background: var(--tint-bg); }
.drop-range { display: none; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px 10px 10px; }
.drop-range.show { display: grid; }
.drop-range-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
}
.drop-range-field input[type="date"] {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--inset);
  border: 1px solid var(--strong-line);
  border-radius: 10px;
  padding: 8px 10px;
}
.drop-label .count { margin-left: auto; font-size: 12.5px; color: var(--tertiary); font-variant-numeric: tabular-nums; }
.drop-sep { height: 1px; margin: 6px 8px; background: var(--hairline); }
.drop-actions { display: flex; gap: 8px; padding: 8px 10px 6px; }
.drop-action { flex: 1; font-size: 13.5px; }
.drop-item {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 15px;
  transition: background var(--fast);
}
.drop-item:hover { background: var(--inset); }
.drop-item svg { color: var(--secondary); flex-shrink: 0; }
.drop-item-danger { color: var(--red); }
.drop-item-danger svg { color: var(--red); }

/* ================= INSTALL + ERRORS ================= */

.install {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  transform: translate(-50%, 24px);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow-pop);
  padding: 10px 10px 10px 16px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}
.install.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.install-text { color: var(--text); font-weight: 500; }

.install-toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -46%);
  width: min(92vw, 380px);
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  box-shadow: var(--shadow-pop);
  padding: 20px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.install-toast.show { opacity: 1; transform: translate(-50%, -50%); pointer-events: auto; }
.install-toast-head { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 12px; }
.install-toast-list { margin: 0 0 16px; padding-left: 20px; color: var(--secondary); font-size: 14.5px; display: grid; gap: 8px; }
.install-toast-close { width: 100%; }

.save-error {
  max-width: 1120px;
  margin: 12px auto 0;
  width: calc(100% - 32px);
  background: var(--red-bg);
  color: var(--red);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14px;
}

/* ================= CONTENT ================= */

.content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 32px);
}

.health-line { font-size: 12.5px; color: var(--secondary); }
.health-line.error { color: var(--red); }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat {
  appearance: none;
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
  transition: border-color var(--fast), transform var(--fast), box-shadow var(--fast);
}
.stat:hover { border-color: var(--strong-line); transform: translateY(-1px); }
.stat:active { transform: scale(0.98); }
.stat.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow); }
.stat .num {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--secondary);
  transition: color var(--fast);
}
.stat .num.active { color: var(--accent); }
.stat.active .num { color: var(--accent); }
.stat .label { font-size: 13px; color: var(--secondary); margin-top: 3px; }

/* List head */
.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 2px 10px;
  font-size: 13px;
  color: var(--secondary);
}

/* Booking list */
.list { display: flex; flex-direction: column; gap: 12px; }

.row {
  position: relative;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: box-shadow var(--fast), transform var(--fast), border-color var(--fast);
}
.row:hover { box-shadow: 0 2px 4px rgba(15, 23, 42, 0.06), 0 12px 32px rgba(15, 23, 42, 0.08); }
.row.is-cancelled { opacity: 0.55; }
.row.is-new { border-left: 3px solid var(--accent); }

.meta-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--secondary); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.from { color: var(--tertiary); }

.tag { font-size: 12px; font-weight: 700; border-radius: 8px; padding: 3px 9px; line-height: 1.3; }
.event-tag { color: var(--accent); background: var(--tint-bg); }
.conf-tag { color: var(--secondary); border: 1px solid var(--hairline); font-weight: 600; }
.auth-tag.ok { color: var(--green); background: var(--green-bg); }
.auth-tag.bad { color: var(--amber); background: var(--amber-bg); }
.cancelled-tag { color: var(--red); font-weight: 700; }

.subject { font-size: 17px; font-weight: 600; line-height: 1.3; }
.guest { font-size: 15px; font-weight: 600; }
.sub { font-size: 14px; color: var(--secondary); }
.notes { font-size: 13px; color: var(--amber); }

.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.action-btn {
  appearance: none;
  border: none;
  background: var(--ctrl);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 40px;
  transition: background var(--fast), transform 0.12s ease;
}
.action-btn:hover { background: var(--tint-bg); }
.action-btn:active { transform: scale(0.97); }
.action-btn.danger { color: var(--red); }
.action-btn.danger:hover { background: var(--red-bg); }
.icon-btn.mini { width: 38px; height: 38px; margin-left: auto; }
.icon-btn.mini:hover { color: var(--red); background: var(--red-bg); }

/* Expanded email */
.email-wrap { background: var(--inset); border-radius: var(--radius-sm); overflow: hidden; margin-top: 2px; }
.trail { padding: 12px 14px; border-bottom: 1px solid var(--hairline); }
.trail-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--tertiary); font-weight: 700; margin-bottom: 6px; }
.trail-item { font-size: 13.5px; color: var(--text); padding: 3px 0; }
.trail-item .from { color: var(--tertiary); }
.email-head { font-size: 13px; color: var(--secondary); padding: 10px 14px; border-bottom: 1px solid var(--hairline); }
.email {
  margin: 0;
  padding: 12px 14px 14px;
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 40vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.empty { padding: 72px 24px; text-align: center; color: var(--secondary); font-size: 15px; line-height: 1.55; }
.empty b { display: block; font-size: 17px; margin-bottom: 6px; color: var(--text); }

/* Footer */
.footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
}
.footer-inner {
  border-top: 1px solid var(--hairline);
  padding: 18px 2px 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  font-size: 12.5px;
  color: var(--tertiary);
}
.footer-brand { display: inline-flex; align-items: center; gap: 8px; }
.footer-brand b { color: var(--secondary); }

/* ================= LARGER SCREENS ================= */

@media (min-width: 620px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 860px) {
  .topbar-inner { padding-top: 10px; }
  .search-wrap { order: 0; flex: 1 1 auto; max-width: 420px; }
  .nav-actions { order: 1; }
  .brand-title { font-size: 21px; }
  .content { padding-top: 22px; }
  .list { display: grid; grid-template-columns: repeat(2, 1fr); align-items: start; }
  .row { flex-basis: 100%; }
  .email { max-height: 340px; }
  .stat .num { font-size: 32px; }
}

@media (min-width: 1120px) {
  .topbar-inner { grid-template-columns: auto 1fr auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .topbar, .install { -webkit-backdrop-filter: none; backdrop-filter: none; }
}