:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --surface: #ffffff;
  --surface-strong: #ecfdf5;
  --ink: #17201d;
  --muted: #63706b;
  --line: #dce4df;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --accent: #b45309;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --shadow: 0 18px 45px rgba(23, 32, 29, 0.08);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 35%),
    radial-gradient(circle at top right, rgba(180, 83, 9, 0.1), transparent 30%),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 14px
    max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(220, 228, 223, 0.9);
  background: rgba(247, 248, 246, 0.9);
  backdrop-filter: blur(18px);
}

.brand,
.topbar-actions,
.workspace-header,
.panel-heading,
.modal-actions,
.admin-summary {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
  line-height: 1.15;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.session-button {
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  padding: 0;
  text-align: left;
}

.session-button:not(:disabled) small {
  color: var(--primary-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.session-button:disabled {
  cursor: default;
}

.brand-mark {
  position: relative;
  display: grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(15, 118, 110, 0.25);
  border-radius: var(--radius);
  background: #e8f7f2;
}

.brand-mark::before,
.brand-mark::after,
.brand-mark span {
  content: "";
  position: absolute;
  bottom: 10px;
  width: 5px;
  border-radius: 4px 4px 1px 1px;
  background: var(--primary);
}

.brand-mark::before {
  left: 12px;
  height: 10px;
}

.brand-mark span {
  left: 18px;
  height: 17px;
}

.brand-mark::after {
  right: 11px;
  height: 24px;
  background: var(--accent);
}

.topbar-actions {
  gap: 10px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.status-pill.offline {
  border-color: rgba(180, 83, 9, 0.35);
  color: var(--accent);
}

.auth-view {
  display: grid;
  min-height: calc(100vh - 69px);
  place-items: center;
  padding: 36px 18px;
}

.auth-panel {
  display: grid;
  width: min(100%, 960px);
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.72fr);
  gap: 22px;
  align-items: stretch;
}

.auth-copy {
  display: flex;
  min-height: 430px;
  flex-direction: column;
  justify-content: end;
  padding: clamp(26px, 5vw, 52px);
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(23, 32, 29, 0.64), rgba(23, 32, 29, 0.4)),
    linear-gradient(135deg, #0f766e, #164e63 52%, #b45309);
  color: #fff;
  box-shadow: var(--shadow);
}

.auth-copy .eyebrow {
  color: rgba(255, 255, 255, 0.78);
}

.auth-copy h1 {
  max-width: 640px;
  margin: 0;
  font-size: clamp(2.35rem, 5vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.auth-copy p:last-child {
  max-width: 570px;
  margin: 18px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 1.04rem;
  line-height: 1.55;
}

.login-card,
.panel,
.modal-form {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.login-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: clamp(22px, 4vw, 34px);
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid #cfd9d3;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.primary-button,
.secondary-button,
.text-button,
.icon-button {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  min-height: 48px;
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.secondary-button {
  background: #fff;
  border-color: #cfd9d3;
  color: var(--ink);
  padding: 9px 13px;
}

.text-button {
  background: transparent;
  color: var(--primary-strong);
  padding: 7px 0;
}

.icon-button {
  background: #fff;
  border-color: #cfd9d3;
  color: var(--ink);
  padding: 8px 12px;
}

.danger-button {
  border-color: var(--danger-soft);
  background: #fff6f5;
  color: var(--danger);
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.form-message.error {
  color: var(--danger);
}

.workspace {
  width: 100%;
  margin: 0 auto;
  min-height: calc(100vh - 69px);
  min-height: calc(100svh - 69px);
  padding: clamp(28px, 4vh, 46px) max(clamp(18px, 3vw, 46px), env(safe-area-inset-right))
    calc(38px + env(safe-area-inset-bottom)) max(clamp(18px, 3vw, 46px), env(safe-area-inset-left));
}

.workspace-header {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.workspace-header h1,
.panel h2,
.modal-form h2 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

.workspace-header h1 {
  font-size: clamp(2rem, 4vw, 3.6rem);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.balance-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(14px, 2vw, 22px);
  margin-bottom: clamp(18px, 3vh, 28px);
}

.balance-card {
  position: relative;
  display: flex;
  min-height: clamp(168px, 20vh, 240px);
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  padding: clamp(18px, 2.4vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(23, 32, 29, 0.06);
}

.balance-card::after {
  content: "";
  position: absolute;
  right: -20px;
  bottom: -28px;
  width: 112px;
  height: 112px;
  border: 18px solid rgba(15, 118, 110, 0.08);
  border-radius: 50%;
}

.balance-card.credit::after {
  border-color: rgba(15, 118, 110, 0.11);
}

.balance-card.debit::after {
  border-color: rgba(22, 78, 99, 0.12);
}

.balance-card.food::after {
  border-color: rgba(180, 83, 9, 0.13);
}

.balance-card span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
  text-transform: uppercase;
}

.balance-card strong {
  display: block;
  margin-top: 14px;
  font-size: clamp(2rem, 3.6vw, 4.3rem);
  line-height: 1;
}

.balance-card small {
  display: block;
  margin-top: 12px;
  color: var(--muted);
}

.content-grid,
.admin-layout {
  display: grid;
  gap: 18px;
}

.content-grid {
  grid-template-columns: minmax(310px, 440px) minmax(0, 1fr);
  align-items: stretch;
}

.panel {
  padding: 18px;
}

.panel-heading {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading h2 {
  font-size: 1.1rem;
}

.panel-heading span,
.panel-heading select {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.purchase-panel {
  display: grid;
  gap: 14px;
}

.history-panel,
.purchase-panel {
  min-height: clamp(320px, calc(100vh - 520px), 560px);
  min-height: clamp(320px, calc(100svh - 520px), 560px);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

td strong {
  display: block;
}

.empty-state {
  margin: 12px 0 0;
  color: var(--muted);
}

.admin-layout {
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  align-items: start;
}

.admin-summary {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.summary-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.users-list {
  display: grid;
  gap: 12px;
}

.user-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.user-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.user-card header strong,
.user-card header span {
  display: block;
}

.user-card header span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.user-card form {
  display: grid;
  gap: 10px;
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

dialog {
  width: min(440px, calc(100% - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(23, 32, 29, 0.42);
  backdrop-filter: blur(3px);
}

.modal-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.modal-actions {
  justify-content: flex-end;
  gap: 10px;
}

.install-steps {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 22px;
  color: var(--ink);
  line-height: 1.45;
}

@media (max-width: 860px) {
  .auth-panel,
  .content-grid,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .auth-copy {
    min-height: 330px;
  }

  .balance-grid {
    grid-template-columns: 1fr;
  }

  .balance-card {
    min-height: clamp(145px, 20vh, 190px);
    min-height: clamp(145px, 20svh, 190px);
  }

  .history-panel,
  .purchase-panel {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
  }

  .brand strong {
    max-width: 170px;
  }

  .workspace-header,
  .user-card header {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-summary {
    justify-content: flex-start;
  }

  .mini-grid {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 560px;
  }
}
