:root {
  --bg: #0f1216;
  --surface: #171b22;
  --surface-2: #1f252f;
  --border: #2a3240;
  --text: #f3f5f8;
  --muted: #9aa5b6;
  --accent: #4f9cf9;
  --accent-soft: rgba(79, 156, 249, 0.16);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.16);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.16);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.16);
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --sidebar-w: 248px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--red); font-size: 0.9rem; margin: 4px 0 0; }

/* Layout principal */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 1.35rem;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  border-color: rgba(79, 156, 249, 0.35);
  color: #fff;
}

.nav-ico { font-size: 1.15rem; width: 24px; text-align: center; }

.nav-pill {
  margin-left: auto;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.78rem;
  font-weight: 700;
}

.nav-item.active .nav-pill {
  background: var(--accent);
  color: #081220;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Main */
.main-area {
  flex: 1;
  min-width: 0;
  padding: 22px 26px 40px;
  max-width: 1320px;
  margin: 0 auto;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: none;
  gap: 8px;
}

.view { display: none; }
.view.active { display: block; }

/* Grids & Cards */
.grid-kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card + .card-spacer { margin-top: 16px; }

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

.card-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.kpi-card:hover { border-color: var(--accent); }
.kpi-card:active { transform: scale(0.99); }

.kpi-label {
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 800;
  margin-top: 6px;
}

.kpi-sub {
  font-size: 0.84rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}

.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--accent-soft); color: var(--accent); }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: #28303d; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #081220; }
.btn-primary:hover { background: #6aaeff; }
.btn-green { background: var(--green-soft); border-color: rgba(52, 211, 153, 0.4); color: var(--green); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 0.86rem; }
.btn-lg { min-height: 50px; width: 100%; font-size: 1rem; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

input, select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 0 12px;
  font-size: 0.95rem;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Filter chips / tabs */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}

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

/* Interactive list rows (touch-friendly) */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s;
}

.check-row:hover { border-color: var(--accent); }
.check-row.is-done { opacity: 0.56; }
.check-row.is-done .row-title { text-decoration: line-through; }

.check-box {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 8px;
  border: 2px solid var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  margin-top: 1px;
}

.check-row.is-done .check-box {
  background: var(--green);
  border-color: var(--green);
  color: #062117;
  font-weight: 900;
}

.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 700; font-size: 0.98rem; }
.row-meta { font-size: 0.84rem; color: var(--muted); margin-top: 3px; }

/* Forms */
.inline-form {
  display: grid;
  grid-template-columns: 2fr 1fr 90px auto;
  gap: 10px;
  margin-bottom: 16px;
}

/* Meals */
.meal-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.meal-card.today-highlight {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(79, 156, 249, 0.1), var(--surface-2));
}

.meal-type {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.meal-dish {
  font-size: 1.04rem;
  font-weight: 700;
  margin: 4px 0 6px;
}

/* Privacy blur */
body.privacy-on .money {
  filter: blur(8px);
  user-select: none;
}

.money-pos { color: var(--green); }
.money-neg { color: var(--red); }

/* Table */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 24px;
  background: #222b38;
  border: 1px solid var(--accent);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-weight: 600;
  z-index: 90;
}

/* PIN Overlay */
.pin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.92);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.pin-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.pin-card input {
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  min-height: 54px;
}

.pin-badge {
  font-weight: 700;
  color: var(--accent);
}

/* Responsivo (celular e tablet retrato) */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: auto;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 50;
  }
  .brand, .sidebar-footer, .nav-pill { display: none; }
  .nav-list {
    flex-direction: row;
    justify-content: space-around;
    gap: 4px;
  }
  .nav-item {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    min-height: 52px;
    font-size: 0.72rem;
    text-align: center;
  }
  .topbar-actions { display: flex; }
  .main-area { padding: 16px 14px 92px; }
  .toast { bottom: 84px; right: 14px; left: 14px; text-align: center; }
}
