:root {
  --color-bg: #F1E3C8;
  --color-surface: #FFFCF5;
  --color-text: #2A2015;
  --color-muted: #7C6A54;
  --color-primary: #A8402A;
  --color-primary-dark: #7E2E1D;
  --color-accent: #46603F;
  --color-accent-dark: #33452E;
  --color-accent-soft: #E1E8D8;
  --color-border: #E2D2AE;
  --color-today: #EFCB86;
  --color-danger: #9A3324;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Karla", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --shadow-card: 0 1px 2px rgba(42, 32, 21, 0.06), 0 10px 24px -14px rgba(42, 32, 21, 0.35);
  --nav-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
}

body {
  background-color: var(--color-bg);
  background-image:
    radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.45), transparent 42%),
    radial-gradient(circle at 85% 8%, rgba(168, 64, 42, 0.08), transparent 45%),
    repeating-linear-gradient(135deg, rgba(42, 32, 21, 0.025) 0px, rgba(42, 32, 21, 0.025) 1px, transparent 1px, transparent 7px);
  background-attachment: fixed;
}

::selection { background: var(--color-primary); color: #fff; }

a { color: var(--color-primary-dark); text-decoration: none; }

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 24px;
  min-height: 100vh;
}
.page.has-nav { padding-bottom: calc(var(--nav-height) + 24px); }

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.page > * { animation: fadeSlideUp 0.5s ease both; }
.page > *:nth-child(1) { animation-delay: 0.02s; }
.page > *:nth-child(2) { animation-delay: 0.08s; }
.page > *:nth-child(3) { animation-delay: 0.14s; }
.page > *:nth-child(4) { animation-delay: 0.20s; }
.page > *:nth-child(n+5) { animation-delay: 0.26s; }
.page > .save-flash { animation: none; }

h1, h2, h3 { font-family: var(--font-display); color: var(--color-text); }
h1 { font-size: 1.9rem; font-weight: 600; margin: 0 0 14px; letter-spacing: -0.01em; }
.page > h1::after {
  content: "";
  display: block;
  width: 40px;
  height: 3px;
  margin-top: 10px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
}
h2 { font-size: 1.1rem; font-weight: 600; margin: 22px 0 8px; color: var(--color-muted); }
h3 { font-size: 1.05rem; font-weight: 600; margin: 0 0 8px; }
.subtitle { color: var(--color-muted); margin: 2px 0 0; }

.auth-screen { text-align: center; padding-top: 8vh; }
.logotype { display: flex; flex-direction: column; align-items: center; margin-bottom: 30px; }
.logotype-mark { font-size: 2.6rem; filter: drop-shadow(0 6px 14px rgba(42, 32, 21, 0.22)); }
.logotype h1 {
  font-size: 2.7rem;
  font-weight: 600;
  margin: 4px 0 0;
}
.logotype-rule {
  width: 56px;
  height: 3px;
  margin: 12px 0 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
}

.auth-tabs { display: flex; gap: 8px; margin: 20px 0; }
.tab-btn {
  flex: 1; padding: 12px; border: 1px solid var(--color-border);
  background: var(--color-surface); border-radius: 10px; font-family: var(--font-body);
  font-weight: 600; font-size: 1rem; color: var(--color-text);
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.tab-btn.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.tab-btn:active { transform: scale(0.97); }

.auth-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-form.hidden { display: none; }
.auth-form label { font-weight: 600; }

.error {
  background: #FBE6E1; color: var(--color-danger); border: 1px solid #F0B8AC;
  padding: 10px 12px; border-radius: 8px;
}

input[type="text"], input[type="password"], input[type="date"] {
  width: 100%; padding: 12px; font-family: var(--font-body); font-size: 1rem;
  border: 1px solid var(--color-border); border-radius: 10px;
  background: var(--color-surface); color: var(--color-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(168, 64, 42, 0.15);
}

button {
  font-family: var(--font-body); font-weight: 700; letter-spacing: 0.01em;
  font-size: 1rem; padding: 12px 16px; border-radius: 10px; border: none;
  background: var(--color-primary); color: #fff; cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.1s ease, filter 0.15s ease;
}
button:hover { filter: brightness(1.06); }
button:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1); }
button:disabled { opacity: 0.35; cursor: default; filter: none; transform: none; }
button.danger { background: var(--color-danger); }

.inline-form { display: flex; gap: 8px; margin-bottom: 16px; }
.inline-form input { flex: 1; }

.calendar {
  background: var(--color-surface); border-radius: 16px; padding: 14px;
  border: 1px solid var(--color-border); box-shadow: var(--shadow-card);
}
.calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.month-label { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.month-nav {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 8px; font-size: 1.3rem; color: var(--color-primary-dark);
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.month-nav:active { background: var(--color-bg); transform: scale(0.94); }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekday { text-align: center; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; color: var(--color-muted); padding: 4px 0; }
.day {
  display: flex; align-items: center; justify-content: center; aspect-ratio: 1;
  border-radius: 8px; color: var(--color-text);
  transition: transform 0.12s ease, background-color 0.15s ease;
}
.day:active { transform: scale(0.92); }
.day.outside { color: var(--color-border); }
.day.today { background: var(--color-today); font-weight: 700; }
.day.selected { background: var(--color-primary); color: #fff; font-weight: 700; }

.selected-date-label {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 1.35rem;
  color: var(--color-primary-dark);
  text-transform: none;
  margin: 22px 0 10px;
}

.category { margin-bottom: 20px; }
.option-list {
  list-style: none; margin: 0; padding: 0; background: var(--color-surface);
  border-radius: 14px; border: 1px solid var(--color-border); overflow: hidden;
  box-shadow: var(--shadow-card);
}
.option-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  transition: background-color 0.15s ease;
}
.option-list li:last-child .option-row { border-bottom: none; }
.option-name { font-weight: 600; }
.option-row.has-quantity .option-name { color: var(--color-primary-dark); }

.stepper { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.stepper-btn {
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  border: 1px solid var(--color-border); background: var(--color-surface);
  color: var(--color-primary-dark); font-size: 1.2rem; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center; box-shadow: none;
}
.stepper-btn:active { transform: scale(0.9); background: var(--color-bg); }
.stepper-value {
  min-width: 22px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--color-muted);
}
.option-row.has-quantity .stepper-value { color: var(--color-primary); }

.empty-hint { color: var(--color-muted); font-style: italic; }

.save-flash {
  position: fixed; left: 50%; bottom: calc(var(--nav-height) + 16px); transform: translate(-50%, 10px);
  background: var(--color-text); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 0.9rem;
  font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease; z-index: 20;
}
.save-flash.visible { opacity: 1; transform: translate(-50%, 0); }
.save-flash.flash-error { background: var(--color-danger); }

.date-picker-form { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.date-picker-form label { font-weight: 700; }
.date-picker-form input { flex: 1; }

.aggregate-list {
  list-style: none; margin: 0; padding: 0; background: var(--color-surface);
  border-radius: 14px; border: 1px solid var(--color-border); overflow: hidden;
  box-shadow: var(--shadow-card);
}
.aggregate-row { padding: 12px 16px; border-bottom: 1px solid var(--color-border); }
.aggregate-list li:last-child { border-bottom: none; }
.aggregate-main { display: flex; align-items: center; justify-content: space-between; }
.option-name { font-weight: 600; }
.count-badge {
  background: var(--color-accent); color: #fff; border-radius: 999px;
  padding: 2px 11px; font-weight: 700; font-size: 0.85rem;
}
.aggregate-row details { margin-top: 6px; }
.aggregate-row summary { color: var(--color-accent-dark); cursor: pointer; font-size: 0.85rem; font-weight: 600; }
.usernames { margin: 6px 0 0; color: var(--color-muted); font-size: 0.9rem; }

.back-link { display: inline-block; margin-bottom: 10px; color: var(--color-muted); font-weight: 600; }
.admin-list { list-style: none; margin: 0; padding: 0; }
.admin-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; flex-wrap: wrap; box-shadow: var(--shadow-card);
}
.admin-row.inactive { opacity: 0.55; }
.admin-row-link { flex: 1; display: flex; justify-content: space-between; align-items: center; color: var(--color-text); }
.admin-row-name { font-weight: 700; }
.admin-row-meta { color: var(--color-muted); font-size: 0.85rem; }
.admin-row-actions { display: flex; gap: 6px; }
.admin-row-actions button { padding: 8px 10px; font-size: 0.9rem; }
.rename-form { display: flex; gap: 6px; flex: 1; min-width: 140px; }
.rename-form input { flex: 1; padding: 8px 10px; }
.badge-inactive { color: var(--color-danger); font-size: 0.8rem; font-weight: 600; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-height);
  background: var(--color-surface); border-top: 1px solid var(--color-border); display: flex; z-index: 10;
  box-shadow: 0 -8px 24px -16px rgba(42, 32, 21, 0.4);
}
.bottom-nav a, .bottom-nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-family: var(--font-body); font-size: 0.7rem; font-weight: 600;
  color: var(--color-muted); background: none; border: none; box-shadow: none; padding: 4px;
  position: relative;
}
.bottom-nav a.active { color: var(--color-accent-dark); }
.bottom-nav a.active::before {
  content: ""; position: absolute; top: 3px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: var(--color-accent);
}
.bottom-nav .icon { font-size: 1.3rem; }
.nav-logout-form { flex: 1; display: flex; }
.nav-logout-form button { width: 100%; }

@media (min-width: 700px) {
  .page { max-width: 600px; padding-top: 32px; }
}
