:root {
  --bg: #f3efe6;
  --bg-deep: #e7e0d2;
  --ink: #1a2424;
  --muted: #5c6a6a;
  --brand: #0f3d3e;
  --brand-soft: #1a5556;
  --accent: #c45c26;
  --accent-soft: #f3d9c8;
  --ok: #1f6b4a;
  --warn: #a15c00;
  --danger: #9b2c2c;
  --card: rgba(255, 252, 246, 0.92);
  --line: rgba(26, 36, 36, 0.1);
  --shadow: 0 10px 30px rgba(15, 61, 62, 0.08);
  --radius: 18px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #d9eee8 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #f6d9c5 0%, transparent 45%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }
h1, h2 { margin: 0; font-family: var(--display); letter-spacing: -0.02em; }
p { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 48px;
  padding: 0.7rem 1.1rem;
  border: 0;
  border-radius: 999px;
  font: 600 0.95rem/1 var(--font);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: #f8f5ef; }
.btn-primary:hover { background: var(--brand-soft); }
.btn-secondary { background: #fff; color: var(--brand); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--brand); min-height: 40px; padding: 0.4rem 0.8rem; }
.btn-block { width: 100%; }

/* Login */
.page-login { display: grid; place-items: center; padding: 1.25rem; }
.login-shell { width: min(100%, 420px); }
.login-panel {
  padding: 1.75rem 1.4rem 1.5rem;
  border-radius: calc(var(--radius) + 6px);
  background: var(--card);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.7);
  animation: rise 0.45s ease both;
}
.brand, .brand-sm {
  margin: 0 0 0.35rem;
  color: var(--brand);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.35rem;
}
.brand-sm { font-size: 1rem; }
.login-panel h1 { font-size: 1.85rem; margin-bottom: 0.45rem; }
.lede, .hint, .meta, .label { color: var(--muted); }
.lede { margin-bottom: 1.25rem; line-height: 1.45; }
.hint { margin-top: 1rem; font-size: 0.85rem; line-height: 1.4; }

.login-form label,
.record-form label {
  display: block;
  margin: 0.85rem 0 0.35rem;
  font-size: 0.88rem;
  font-weight: 600;
}
.login-form input,
.filters input,
.filters select,
.record-form input,
.record-form select,
.record-form textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: 1rem/1.3 var(--font);
}
.record-form textarea { min-height: 96px; resize: vertical; }
.login-form input { font-size: 1.6rem; letter-spacing: 0.35em; text-align: center; }
.login-form .btn { margin-top: 1.1rem; }

.alert {
  padding: 0.85rem 1rem;
  border-radius: 14px;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert-error { background: #f8e4e4; color: var(--danger); }

/* App chrome */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: rgba(243, 239, 230, 0.85);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  width: min(920px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.9rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.greeting { font-size: 1.35rem; }
.back-link {
  display: inline-block;
  margin-bottom: 0.25rem;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.9rem;
}

.app-main {
  width: min(920px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 calc(5.5rem + var(--safe-bottom));
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.stat {
  padding: 0.85rem 0.7rem;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.65);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.4s ease both;
}
.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.1s; }
.stat:nth-child(4) { animation-delay: 0.15s; }
.stat-value {
  display: block;
  font-family: var(--display);
  font-size: 1.45rem;
  color: var(--brand);
}
.stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-attention .stat-value { color: var(--warn); }
.stat-danger .stat-value { color: var(--danger); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: stretch;
  margin-bottom: 1rem;
}
.filters {
  flex: 1 1 280px;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr auto;
  gap: 0.5rem;
}

.customer-list { display: grid; gap: 0.75rem; }
.customer-card {
  display: block;
  padding: 1rem 1.05rem;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
  animation: rise 0.35s ease both;
}
.customer-card:active { transform: scale(0.99); }
.customer-card:hover { border-color: rgba(15, 61, 62, 0.25); }
.customer-card-top, .customer-card-bottom {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.customer-card h2 { font-size: 1.15rem; margin-bottom: 0.2rem; }
.meta { font-size: 0.88rem; }
.customer-card-bottom {
  margin-top: 0.85rem;
  flex-wrap: wrap;
  align-items: center;
}
.money, .due { font-size: 0.85rem; color: var(--muted); margin-left: auto; }
.due { margin-left: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-new { background: #dceeee; color: var(--brand); }
.badge-ready { background: var(--accent-soft); color: var(--accent); }
.badge-done { background: #d9efe4; color: var(--ok); }
.badge-cancelled { background: #eee; color: #666; }
.badge-warn { background: #ffe8c7; color: var(--warn); }
.badge-muted { background: #eceae4; color: var(--muted); }

.empty-state {
  text-align: center;
  padding: 2.5rem 1.25rem;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px dashed rgba(15, 61, 62, 0.2);
}
.empty-state h2 { margin-bottom: 0.4rem; }
.empty-state p { margin-bottom: 1rem; color: var(--muted); }

.fab {
  position: fixed;
  right: 1.1rem;
  bottom: calc(1.1rem + var(--safe-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  font-weight: 500;
  box-shadow: 0 12px 28px rgba(196, 92, 38, 0.35);
  z-index: 30;
}

/* Form */
.readonly-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.readonly-strip > div {
  padding: 0.75rem;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.7);
}
.readonly-strip .label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.record-form fieldset {
  margin: 0 0 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
.record-form legend {
  padding: 0 0.35rem;
  font-family: var(--display);
  font-weight: 700;
  color: var(--brand);
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.check {
  display: flex !important;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  font-weight: 500 !important;
}
.check input { width: auto; min-height: auto; }
.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  position: sticky;
  bottom: calc(0.75rem + var(--safe-bottom));
  padding: 0.75rem;
  border-radius: 16px;
  background: rgba(243, 239, 230, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
}

.toast-stack {
  position: fixed;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  width: min(420px, calc(100% - 1.5rem));
  display: grid;
  gap: 0.5rem;
}
.toast {
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease both;
  font-size: 0.92rem;
}
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warn); }
.toast-success { background: var(--ok); }
.toast-info { background: var(--brand-soft); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .btn { grid-column: 1 / -1; }
  .readonly-strip { grid-template-columns: 1fr 1fr; }
  .toolbar > .btn-primary { display: none; }
  .money { margin-left: 0; }
}

@media (min-width: 761px) {
  .fab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Admin + settings */
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
}
.admin-nav a:not(.btn) {
  color: var(--brand);
  padding: 0.35rem 0.5rem;
}
.stats-admin { grid-template-columns: repeat(3, 1fr); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.section-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.section-btn {
  min-height: 42px;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
  font: 600 0.9rem var(--font);
  display: inline-flex;
  align-items: center;
}
.section-btn.is-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.admin-menu-wrap {
  position: relative;
  z-index: 40;
}
.menu-toggle {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  display: grid;
  place-content: center;
  gap: 5px;
  cursor: pointer;
  padding: 0;
}
.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--brand);
  border-radius: 2px;
}
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 36, 36, 0.28);
  z-index: 45;
}
.menu-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 180px;
  padding: 0.4rem;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 50;
  display: grid;
}
.menu-panel[hidden],
.menu-backdrop[hidden] { display: none !important; }
.menu-item {
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  font-weight: 600;
  color: var(--brand);
}
.menu-item:hover,
.menu-item.is-active { background: rgba(15, 61, 62, 0.08); }

.password-panel h2,
.panel > h2 {
  font-size: 1.15rem;
  margin-bottom: 0.35rem;
}
.password-form { margin-top: 0.5rem; }
.password-form .form-actions { position: static; }

.panel {
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.panel-head h2 { font-size: 1.15rem; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th,
.data-table td {
  text-align: left;
  padding: 0.7rem 0.65rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.data-table tbody tr {
  cursor: pointer;
  transition: background 0.12s ease;
}
.data-table tbody tr:hover { background: rgba(15, 61, 62, 0.05); }

.filters-admin {
  display: grid;
  grid-template-columns: 1.5fr 1fr auto;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.card-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(15, 61, 62, 0.06);
  font-size: 0.78rem;
}
.chip em {
  font-style: normal;
  color: var(--muted);
  font-weight: 600;
}

.field-hint {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.field-hint-inline {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.8rem;
}

.settings-intro { margin-bottom: 1rem; line-height: 1.45; }
.settings-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.tab-btn {
  min-height: 42px;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font: 600 0.9rem var(--font);
  color: var(--brand);
  cursor: pointer;
}
.tab-btn.is-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.settings-panel { display: none; }
.settings-panel.is-active { display: block; }
.sortable-fields {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.settings-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  cursor: grab;
}
.settings-row.is-dragging { opacity: 0.55; }
.drag-handle {
  color: var(--muted);
  font-weight: 700;
  letter-spacing: -0.1em;
  user-select: none;
}
.settings-row-main strong { display: block; }
.settings-row-main .meta { font-size: 0.78rem; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0 !important;
  white-space: nowrap;
}
.toggle input { width: auto; min-height: auto; }
.settings-actions { flex-wrap: wrap; justify-content: flex-start; }

@media (max-width: 760px) {
  .stats-admin { grid-template-columns: repeat(2, 1fr); }
  .filters-admin { grid-template-columns: 1fr; }
  .settings-row {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "handle main"
      "handle toggles";
  }
  .drag-handle { grid-area: handle; }
  .settings-row-main { grid-area: main; }
  .settings-row .toggle { justify-self: start; }
}
