:root {
  --bg: #f3efe9;
  --bg-accent: #ece6df;
  --surface: #ffffff;
  --surface-muted: #f8f6f3;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #b1222c;
  --primary-strong: #8d1a23;
  --accent: #2f7d45;
  --accent-strong: #256237;
  --danger: #b42318;
  --success: #16784a;
  --border: #e7ddd2;
  --ring: rgba(177, 34, 44, 0.22);
  --shadow-soft: 0 6px 20px rgba(31, 41, 55, 0.06);
  --shadow-medium: 0 10px 30px rgba(31, 41, 55, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", "Inter", "Roboto", sans-serif;
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 10px;
  color: var(--muted);
}

/* Desktop Backoffice */

body.app-desktop {
  background:
    radial-gradient(1000px 520px at 100% -40px, rgba(177, 34, 44, 0.08), transparent 60%),
    radial-gradient(820px 460px at -12% -20px, rgba(47, 125, 69, 0.08), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
}

.layout {
  min-height: 100vh;
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 18px;
}

.sidebar {
  position: sticky;
  top: 18px;
  align-self: start;
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-link {
  margin-bottom: 18px;
}

.brand img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

.nav-group {
  margin-bottom: 16px;
}

.nav-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0 8px;
}

.nav-link {
  display: block;
  border-radius: 10px;
  padding: 9px 11px;
  margin-bottom: 5px;
  color: #344154;
  transition: background 0.16s ease, color 0.16s ease;
}

.nav-link:hover,
.nav-link.active {
  background: #f4f1ec;
  color: #182534;
}

.content {
  min-width: 0;
  padding: 4px;
}

.desktop-topbar {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.desktop-eyebrow {
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.desktop-title {
  margin: 0;
  font-size: 24px;
  color: #111827;
}

.desktop-topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.content-stack {
  display: block;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 18px;
  margin-bottom: 16px;
  min-width: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.page-head h1 {
  margin: 0;
  font-size: 28px;
}

.page-desc {
  margin-top: 6px;
  color: #59677a;
}

.section-title {
  margin: 0 0 10px;
  font-size: 20px;
}

.kpi-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat-card {
  background: linear-gradient(180deg, #ffffff 0%, #fbf9f6 100%);
  border: 1px solid #ece3da;
  border-radius: 12px;
  padding: 12px;
}

.stat-card-value {
  margin-top: 6px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.two-col {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pager {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.mini-list {
  display: grid;
  gap: 8px;
}

.mini-list-item {
  border: 1px solid #ece3da;
  background: #fff;
  border-radius: 10px;
  padding: 9px 10px;
}

.export-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.export-card {
  border: 1px solid #ece3da;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.export-card-title {
  font-weight: 800;
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.metric {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.metric h2 {
  margin: 8px 0 2px;
  font-size: 26px;
}

/* Buttons */

button,
.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.16s ease;
}

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

button:active,
.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--accent);
}

.btn-secondary:hover {
  background: var(--accent-strong);
}

.btn-muted {
  background: #7f7166;
}

.btn-muted:hover {
  background: #655a51;
}

/* Forms */

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: #111827;
  padding: 10px 12px;
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 800;
  color: #16212f;
}

label small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin-right: 6px;
  accent-color: var(--primary);
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.app-desktop .form-grid input[type="number"],
body.app-desktop .form-grid input[type="date"],
body.app-desktop .form-grid input[type="time"],
body.app-desktop .form-grid input[type="datetime-local"] {
  max-width: 240px;
}

body.app-desktop .panel form[method="get"] {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

body.app-desktop .panel form[method="get"] input[type="text"] {
  max-width: 380px;
}

.panel form {
  display: block;
}

.panel form p {
  margin: 0 0 12px;
}

.panel form p input:not([type="checkbox"]):not([type="radio"]),
.panel form p select,
.panel form p textarea {
  max-width: 560px;
}

.panel form p input[type="number"],
.panel form p input[type="date"],
.panel form p input[type="time"],
.panel form p input[type="datetime-local"] {
  max-width: 230px;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  max-width: 100%;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

/* Lists / tables */

.table-wrap {
  overflow: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid #efe7de;
  font-size: 14px;
  vertical-align: top;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #566273;
  background: #faf8f5;
}

tbody tr:hover {
  background: #fcfbf9;
}

/* Tags, feedback, chips */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  background: #eee8df;
  color: #4a3f35;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  max-width: 100%;
}

.alert,
.success {
  border-radius: 11px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 14px;
}

.alert {
  background: #fef1f1;
  border: 1px solid #f7d5d5;
  color: #962a2a;
}

.success {
  background: #ebf9ef;
  border: 1px solid #c9ecd4;
  color: #145a37;
}

.flash-wrap {
  margin-bottom: 10px;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: #273446;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}

.chip:hover {
  background: #f7f5f2;
}

.chip-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.action-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Stepper / weather */

.stepper-wrap {
  display: grid;
  grid-template-columns: 1fr 1.6fr 1fr;
  gap: 8px;
  align-items: center;
}

.stepper-btn {
  min-height: 46px;
  font-size: 18px;
}

.stepper-value {
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.weather-card-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.weather-card {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.weather-card-day {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.weather-card-icon {
  font-size: 26px;
  line-height: 1;
}

.weather-card-label {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
}

.weather-card-temp {
  margin-top: 8px;
  font-size: 18px;
  font-weight: 800;
}

.weather-card-trend {
  margin-top: 8px;
  font-size: 12px;
  color: #374151;
}

.weather-card-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

/* Mobile PWA */

body.app-mobile {
  background: linear-gradient(180deg, #f2ede7 0%, #ece5dc 100%);
}

.mobile-shell {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 14px 12px 100px;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.mobile-header h1 {
  margin: 4px 0 0;
  font-size: 18px;
}

.mobile-header .btn {
  padding: 8px 12px;
  font-size: 13px;
}

.mobile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  padding: 14px;
  margin-bottom: 12px;
}

.mobile-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.mobile-btn {
  min-height: 60px;
  border-radius: 14px;
  font-size: 18px;
  font-weight: 800;
}

.mobile-status-grid {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 -6px 20px rgba(31, 41, 55, 0.1);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
  text-align: center;
  padding: 12px 6px;
  font-size: 12px;
  color: #6b7280;
  font-weight: 700;
}

.bottom-nav a.active {
  background: var(--primary);
  color: #fff;
}

/* Auth */

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(700px 380px at 50% -120px, rgba(177, 34, 44, 0.14), transparent 65%),
    linear-gradient(180deg, #f4efe8 0%, #ebe3d9 100%);
}

.auth-card {
  width: 100%;
  max-width: 440px;
}

.auth-brand {
  margin-bottom: 14px;
}

.auth-title {
  margin-top: 0;
}

/* Responsive */

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 250px minmax(0, 1fr);
    padding: 14px;
  }
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
  }

  .sidebar {
    display: none;
  }

  .content {
    padding: 0;
  }

  .desktop-topbar {
    margin-bottom: 10px;
  }

  .desktop-title {
    font-size: 20px;
  }

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