:root {
  color-scheme: light;
  --navy: #18324a;
  --navy-deep: #102438;
  --blue: #24658c;
  --cream: #f6f2e9;
  --surface: #ffffff;
  --line: #d8dee3;
  --ink: #17212b;
  --muted: #5b6874;
  --danger: #a32626;
  --success: #24703c;
  --shadow: 0 12px 34px rgba(16, 36, 56, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--cream); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background: linear-gradient(145deg, #fbf8f1 0%, #edf3f5 100%);
}

body[data-company="LOAH"] {
  --navy: #252525;
  --navy-deep: #080808;
  --blue: #3e3e3e;
  --cream: #f3f3f1;
  --line: #c9c9c6;
  --ink: #171717;
  --muted: #5d5d5a;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.14);
  background: linear-gradient(145deg, #ffffff 0%, #e8e8e5 100%);
}

button,
input,
select,
textarea { font: inherit; }

button,
.back-link {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  font-weight: 700;
}

button:hover { filter: brightness(0.94); }
button:disabled { cursor: wait; opacity: 0.62; }

:focus-visible {
  outline: 3px solid #ed9c2b;
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.75rem;
  transform: translateY(-160%);
  background: #fff;
  color: var(--navy);
}

.skip-link:focus { transform: translateY(0); }

.login-layout {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.25rem;
}

.login-card {
  width: min(100%, 430px);
  padding: clamp(1.4rem, 5vw, 2.6rem);
  border: 1px solid rgba(24, 50, 74, 0.1);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.brand-logo { display: block; max-width: 180px; max-height: 72px; object-fit: contain; }
.eyebrow { margin: 1.25rem 0 0.25rem; color: var(--blue); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; color: var(--navy-deep); font-size: clamp(1.55rem, 4vw, 2.25rem); }
h2 { margin: 0; color: var(--navy-deep); }

form label,
fieldset legend { display: block; margin: 0.8rem 0 0.35rem; font-weight: 700; }

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #aeb9c2;
  border-radius: 9px;
  padding: 0.65rem 0.75rem;
  color: var(--ink);
  background: #fff;
}

textarea { min-height: 92px; resize: vertical; }
.login-card form button { width: 100%; margin-top: 1.2rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.8rem;
  color: var(--navy);
  background: transparent;
  text-decoration: underline;
}

.admin-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(clamp(1rem, 3vw, 2rem), env(safe-area-inset-right))
    0.75rem
    max(clamp(1rem, 3vw, 2rem), env(safe-area-inset-left));
  color: #fff;
  background: var(--navy-deep);
}

.company-switch {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
}

.company-switch select {
  min-width: 7rem;
  font: inherit;
  font-weight: 800;
}

.brand { display: flex; align-items: center; gap: 0.8rem; color: #fff; text-decoration: none; }
.brand img { width: 72px; height: 42px; padding: 0.25rem; border-radius: 7px; object-fit: contain; background: #fff; }
.brand span { display: grid; }
.brand small { opacity: 0.76; }
body[data-company="LOAH"] .topbar { box-shadow: inset 0 -3px 0 #b8b8b1; }
body[data-company="LOAH"] .company-switch select { border-color: #a4a4a0; }
.session-actions { display: flex; align-items: center; gap: 0.7rem; }
.button-secondary { border: 1px solid currentColor; color: var(--navy); background: #fff; }
.topbar .button-secondary { color: #fff; background: transparent; }
.button-danger { background: var(--danger); }

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1.25rem 0.8rem;
  background: var(--navy);
}

.side-nav button { justify-content: flex-start; text-align: left; background: transparent; scroll-snap-align: center; }
.side-nav button[aria-current="page"] { color: var(--navy-deep); background: #fff; }

.content { min-width: 0; padding: clamp(1rem, 3vw, 2rem); }
.view { max-width: 1220px; margin: 0 auto; }
.feedback { max-width: 1220px; margin: 0 auto; }
.message { min-height: 1.3em; margin: 0 0 0.5rem; color: var(--success); }
.message.error { color: var(--danger); }
.muted { color: var(--muted); }

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

.export-actions,
.adjustment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.audit-filters { grid-template-columns: repeat(2, minmax(0, 260px)) auto !important; }

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

.summary-card,
.table-card {
  border: 1px solid rgba(24, 50, 74, 0.1);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card { padding: 1.2rem; }
.summary-card strong { display: block; margin-top: 0.3rem; color: var(--navy-deep); font-size: 2rem; }
.table-card { margin-top: 1rem; overflow: hidden; }
.table-scroll { max-width: 100%; overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
caption { padding: 1rem; color: var(--navy); font-size: 1.05rem; font-weight: 800; text-align: left; }
th, td { padding: 0.8rem; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--navy); background: #f1f5f7; font-size: 0.82rem; text-transform: uppercase; }
td .row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.row-actions button { min-height: 44px; padding: 0.45rem 0.65rem; font-size: 0.86rem; }
.state-pill { display: inline-flex; border-radius: 999px; padding: 0.25rem 0.55rem; background: #e6edf2; font-size: 0.82rem; font-weight: 800; }
.state-pill.active { color: #16542b; background: #dcefe1; }
.state-pill.alert { color: #782020; background: #f7dede; }

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 0.7rem;
  padding: 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
}

.filters.compact { grid-template-columns: minmax(0, 230px) auto; justify-content: start; }
.filters label { margin-top: 0; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; padding: 0.8rem; }
.pagination span { color: var(--muted); }

dialog {
  width: min(calc(100% - 2rem), 760px);
  max-height: calc(100vh - 2rem);
  border: 0;
  border-radius: 16px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
}

dialog::backdrop { background: rgba(7, 18, 29, 0.68); }
.dialog-form { max-height: calc(100vh - 2rem); padding: 1.25rem; overflow-y: auto; }
.dialog-form > header,
.dialog-form > footer { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; }
.dialog-form > footer { justify-content: flex-end; margin-top: 1.2rem; }
.icon-button { width: 44px; padding: 0; font-size: 1.5rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 0.8rem; }
fieldset { margin-top: 1rem; border: 1px solid var(--line); border-radius: 10px; }
.days { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.days label { display: inline-flex; align-items: center; gap: 0.3rem; margin: 0; min-height: 44px; }
.days input { width: 22px; min-height: 22px; }
.pairing-qr { display: block; width: min(100%, 320px); margin: 1rem auto; }
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 0.55rem 1rem; }
.detail-list dt { font-weight: 800; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .side-nav {
    position: sticky;
    z-index: 20;
    top: 0;
    flex-direction: row;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    padding: 0.65rem max(0.65rem, env(safe-area-inset-right)) 0.65rem max(0.65rem, env(safe-area-inset-left));
    box-shadow: 0 5px 16px rgba(16, 36, 56, 0.2);
  }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav button { flex: 0 0 auto; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .table-card {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .table-scroll {
    overflow: visible;
  }

  .table-scroll table,
  .table-scroll tbody,
  .table-scroll tr,
  .table-scroll td {
    display: block;
    width: 100%;
  }

  .table-scroll thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .table-scroll caption {
    margin-bottom: 0.65rem;
    border: 1px solid rgba(24, 50, 74, 0.1);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .table-scroll tbody {
    display: grid;
    gap: 0.75rem;
  }

  .table-scroll tr {
    overflow: hidden;
    border: 1px solid rgba(24, 50, 74, 0.12);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .table-scroll td {
    display: grid;
    grid-template-columns: minmax(7rem, 38%) minmax(0, 1fr);
    gap: 0.7rem;
    min-height: 44px;
    padding: 0.7rem 0.8rem;
    border-top: 1px solid var(--line);
    overflow-wrap: anywhere;
  }

  .table-scroll td:first-child {
    border-top: 0;
  }

  .table-scroll td::before {
    content: attr(data-label);
    color: var(--navy);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .table-scroll td[colspan] {
    display: block;
    min-height: 0;
  }

  .table-scroll td[colspan]::before {
    content: none;
  }

  .table-scroll .row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-scroll .row-actions button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .topbar { align-items: flex-start; }
  .brand span { display: none; }
  .session-actions { align-items: flex-end; flex-direction: column; }
  .content {
    padding: 0.8rem max(0.8rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(0.8rem, env(safe-area-inset-left));
  }
  .section-heading { align-items: stretch; flex-direction: column; }
  .section-heading > button { width: 100%; }
  .export-actions,
  .adjustment-actions { flex-direction: column; }
  .export-actions button,
  .adjustment-actions button { width: 100%; min-height: 44px; }
  .summary-grid,
  .filters,
  .filters.compact,
  .audit-filters,
  .form-grid { grid-template-columns: 1fr; }
  .filters > button { width: 100%; }
  .summary-card strong { font-size: 1.65rem; }
  .pagination { justify-content: center; flex-wrap: wrap; }

  dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    max-height: calc(100dvh - env(safe-area-inset-top));
    border-radius: 16px 16px 0 0;
  }

  .dialog-form {
    max-height: calc(100dvh - env(safe-area-inset-top));
    padding: 1rem max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    overflow-y: auto;
  }

  .dialog-form > header {
    position: sticky;
    z-index: 2;
    top: -1rem;
    margin: -1rem -1rem 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .dialog-form > footer { align-items: stretch; flex-direction: column-reverse; }
  .dialog-form > footer {
    position: sticky;
    z-index: 2;
    bottom: -1rem;
    margin: 1rem -1rem -1rem;
    padding: 0.8rem 1rem max(0.8rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .dialog-form > footer button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
