:root {
  --green-950: #031f18;
  --green-900: #073426;
  --green-800: #0b4a36;
  --gold-500: #d4a94f;
  --gold-300: #f0d78c;
  --ivory: #fff8e6;
  --paper: #fffaf0;
  --line: rgba(16, 38, 31, 0.14);
  --muted: #6d756f;
  --ink: #17211d;
  --danger: #a33b31;
  --shadow: 0 22px 60px rgba(2, 24, 17, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 18.5rem minmax(0, 1fr);
  background: linear-gradient(135deg, #fbf7ed, #eee7d8);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.auth-only {
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  background: linear-gradient(180deg, var(--green-950), var(--green-900));
}

body.auth-only .sidebar {
  position: static;
  height: auto;
  padding: 2rem 1.25rem 0;
  background: transparent;
  align-items: center;
}

body.auth-only .brand {
  width: min(28rem, 100%);
  border-bottom: 0;
}

body.auth-only nav,
body.auth-only .security-card,
body.auth-only .topbar,
body.auth-only .warning,
body.auth-only .view {
  display: none !important;
}

body.auth-only main {
  width: min(38rem, 100%);
  margin: 0 auto;
  padding: 1.25rem;
}

body.auth-only #authPanel {
  display: block;
}

button,
input,
select {
  font: inherit;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.25rem;
  background: linear-gradient(180deg, var(--green-950), var(--green-900));
  color: var(--ivory);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.brand {
  display: grid;
  grid-template-columns: 4rem 1fr;
  gap: 0.8rem;
  align-items: center;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(240, 215, 140, 0.22);
}

.brand img {
  width: 4rem;
  height: 5.5rem;
  object-fit: contain;
}

.brand span,
.eyebrow,
.security-card span {
  color: var(--gold-500);
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand strong,
h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
}

.brand strong {
  color: var(--ivory);
  line-height: 1.08;
}

nav {
  display: grid;
  gap: 0.45rem;
}

nav button,
.menu,
.topbar button,
.topbar select,
.panel button,
.panel select {
  border: 1px solid transparent;
  border-radius: 0.5rem;
  min-height: 2.65rem;
  padding: 0 0.85rem;
}

nav button {
  background: transparent;
  color: rgba(255, 248, 230, 0.82);
  text-align: left;
}

nav button.active,
nav button:hover {
  background: rgba(240, 215, 140, 0.12);
  border-color: rgba(240, 215, 140, 0.24);
  color: var(--ivory);
}

.security-card {
  margin-top: auto;
  border: 1px solid rgba(240, 215, 140, 0.25);
  border-radius: 0.5rem;
  padding: 0.95rem;
  background: rgba(255, 248, 230, 0.05);
}

main {
  padding: 1.25rem;
  min-width: 0;
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.25rem;
  font-size: clamp(2rem, 4vw, 3.2rem);
}

h2 {
  margin-bottom: 0;
}

.actions {
  display: flex;
  gap: 0.75rem;
  align-items: end;
}

.actions label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.auth-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
}

.auth-form label {
  display: grid;
  gap: 0.3rem;
  min-width: min(22rem, 100%);
  color: var(--muted);
  font-size: 0.8rem;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.72rem 0.8rem;
  background: rgba(255, 255, 255, 0.82);
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
}

.password-field button,
.link-button {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0 0.75rem;
  background: rgba(255, 255, 255, 0.82);
  color: var(--green-900);
  font-weight: 800;
}

.auth-error {
  flex-basis: 100%;
  margin: 0;
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 750;
}

.auth-error:empty {
  display: none;
}

.link-button {
  min-height: 2.3rem;
  margin-top: 0.75rem;
  background: transparent;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.menu {
  display: none;
  background: white;
  border-color: var(--line);
}

.warning,
.panel,
.metric,
.card {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: rgba(255, 252, 244, 0.88);
  box-shadow: var(--shadow);
}

.warning {
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  border-left: 0.28rem solid var(--gold-500);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics,
.overview-grid,
.records {
  display: grid;
  gap: 0.85rem;
}

.metrics {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.overview-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.records {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric,
.card,
.panel {
  padding: 1rem;
}

.metric strong {
  display: block;
  margin: 0.25rem 0;
  font-size: 1.55rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(18rem, 0.65fr);
  gap: 1rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.panel-actions,
.field-with-action {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  justify-content: flex-end;
}

.field-with-action label {
  flex: 1 1 13rem;
}

.field-with-action button {
  min-height: 2.7rem;
  white-space: nowrap;
}

.card {
  display: grid;
  gap: 0.65rem;
  text-align: left;
}

.record-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: rgba(255, 252, 244, 0.88);
  box-shadow: var(--shadow);
  color: inherit;
  cursor: pointer;
}

.record-card:hover {
  border-color: rgba(212, 169, 79, 0.55);
}

.card h3 {
  margin: 0;
}

.card p,
.note,
.stack span {
  color: var(--muted);
  line-height: 1.42;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.65rem;
  border-radius: 999px;
  padding: 0 0.65rem;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--green-950);
  background: rgba(212, 169, 79, 0.22);
}

.badge.green {
  background: rgba(34, 122, 88, 0.14);
  color: #0d563e;
}

.badge.red {
  background: rgba(163, 59, 49, 0.12);
  color: var(--danger);
}

.stack,
.timeline {
  display: grid;
  gap: 0.65rem;
}

.stack div,
.timeline article {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.55);
}

.timeline article {
  display: grid;
  grid-template-columns: 10rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
}

.calendar-panel {
  overflow: hidden;
}

.calendar-head {
  align-items: center;
}

.calendar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.calendar-controls button,
.calendar-controls select,
.dialog-head button,
.panel-actions button,
.field-with-action button,
.primary-action {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  min-height: 2.5rem;
  padding: 0 0.75rem;
  background: rgba(255, 255, 255, 0.82);
}

.primary-action {
  border-color: rgba(212, 169, 79, 0.45);
  background: var(--green-900);
  color: var(--ivory);
  font-weight: 850;
}

.calendar-status-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.55);
}

.calendar-status-row span {
  color: var(--muted);
}

.calendar-grid {
  display: grid;
  gap: 0.55rem;
}

.calendar-month {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-weekday {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calendar-day,
.calendar-week-column {
  min-height: 8.75rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.55rem;
  background: rgba(255, 255, 255, 0.55);
}

.calendar-day.muted-day {
  opacity: 0.55;
}

.calendar-day-number {
  margin-bottom: 0.45rem;
  color: var(--green-900);
  font-weight: 850;
}

.calendar-day-events,
.calendar-week-events {
  display: grid;
  gap: 0.35rem;
}

.calendar-event,
.agenda-row button {
  display: grid;
  gap: 0.12rem;
  width: 100%;
  border: 1px solid rgba(7, 52, 38, 0.12);
  border-left-width: 0.3rem;
  border-radius: 0.45rem;
  padding: 0.45rem 0.5rem;
  background: white;
  color: var(--ink);
  text-align: left;
}

.calendar-event strong,
.agenda-row button strong {
  font-size: 0.82rem;
}

.calendar-event span,
.calendar-event small,
.agenda-row button span,
.agenda-row button small,
.calendar-more {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.25;
}

.calendar-event em {
  color: var(--danger);
  font-size: 0.7rem;
  font-style: normal;
  font-weight: 850;
}

.status-inquiry {
  border-left-color: #8a7d68;
}

.status-confirmed {
  border-left-color: #2f76a8;
}

.status-paid,
.status-returned {
  border-left-color: #227a58;
}

.status-delivered {
  border-left-color: var(--gold-500);
}

.status-cancelled,
.status-overdue {
  border-left-color: var(--danger);
}

.calendar-week {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: start;
}

.calendar-week-column header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
}

.calendar-week-column header span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calendar-week-column header strong {
  font-size: 1.35rem;
}

.calendar-agenda {
  gap: 0.65rem;
}

.agenda-row {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0.75rem;
  align-items: stretch;
  border-left: 0.3rem solid var(--line);
  border-radius: 0.45rem;
  padding: 0.65rem;
  background: rgba(255, 255, 255, 0.6);
}

.agenda-row time {
  display: grid;
  align-content: center;
  gap: 0.15rem;
}

.agenda-row time span {
  color: var(--muted);
}

.reservation-dialog {
  width: min(46rem, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 1rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.reservation-dialog::backdrop {
  background: rgba(3, 31, 24, 0.55);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.dialog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.dialog-grid div {
  display: grid;
  gap: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.65);
}

.dialog-grid span {
  color: var(--muted);
  line-height: 1.35;
}

.dialog-grid label {
  display: grid;
  gap: 0.3rem;
}

.dialog-grid label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.dialog-grid textarea {
  min-height: 6rem;
  resize: vertical;
}

.dialog-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.65rem;
  margin-top: 1rem;
  align-items: center;
}

.dialog-actions button,
.danger-button {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  min-height: 2.55rem;
  padding: 0 0.85rem;
  background: rgba(255, 255, 255, 0.82);
  color: var(--green-900);
  font-weight: 800;
}

.danger-button {
  color: var(--danger);
}

.dialog-grid input:disabled,
.dialog-grid select:disabled,
.dialog-grid textarea:disabled {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.45);
}

.dialog-wide {
  grid-column: 1 / -1;
}

.warning-inline {
  border-left: 0.3rem solid var(--danger) !important;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: 24rem;
  padding: 0.85rem 1rem;
  border-radius: 0.5rem;
  background: var(--green-950);
  color: var(--ivory);
  box-shadow: var(--shadow);
  transform: translateY(150%);
  transition: transform 180ms ease;
}

.toast.show {
  transform: translateY(0);
}

.app-error {
  left: 1rem;
  right: auto;
  bottom: 1rem;
  max-width: min(34rem, calc(100vw - 2rem));
  background: var(--danger);
}

@media (max-width: 1120px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 10;
    inset: 0 auto 0 0;
    width: min(20rem, 84vw);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu {
    display: inline-flex;
    align-items: center;
  }

  .metrics,
  .overview-grid,
  .records {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  main {
    padding: 0.8rem;
  }

  .topbar,
  .actions,
  .panel-head,
  .layout,
  .calendar-status-row,
  .agenda-row,
  .dialog-head,
  .dialog-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .metrics,
  .overview-grid,
  .records,
  .timeline article,
  .calendar-month,
  .calendar-week {
    grid-template-columns: 1fr;
  }

  .calendar-weekday {
    display: none;
  }

  .calendar-day {
    min-height: auto;
  }

  .calendar-controls {
    justify-content: stretch;
  }

  .calendar-controls button,
  .calendar-controls select {
    flex: 1 1 7rem;
  }
}
