:root {
  --background: #f8fafc;
  --foreground: #0f172a;
  --card: #ffffff;
  --border: #e2e8f0;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: rgba(13, 148, 136, 0.1);
  --muted: #f1f5f9;
  --muted-foreground: #64748b;
  --destructive: #ef4444;
  --destructive-light: rgba(239, 68, 68, 0.1);
  --emerald: #059669;
  --emerald-light: #d1fae5;
  --blue-light: #dbeafe;
  --blue: #1d4ed8;
  --amber-light: #fef3c7;
  --amber: #b45309;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 15px;
}

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

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

.sidebar {
  width: 256px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform .25s ease;
}

.sidebar-brand {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
}

.sidebar-nav { flex: 1; padding: 24px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  font-weight: 500; font-size: .9rem;
  color: var(--muted-foreground);
}
.nav-item:hover { background: var(--muted); color: var(--foreground); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }
.sidebar-user { display: flex; align-items: center; gap: 12px; padding: 0 8px 16px; }
.sidebar-user .avatar {
  width: 32px; height: 32px; border-radius: 999px; background: var(--primary-light);
  color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.sidebar-user .name { font-size: .875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .role { font-size: .75rem; color: var(--muted-foreground); }

.btn-logout {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px; border-radius: 8px; border: 1px solid var(--border); background: white;
  color: var(--muted-foreground); font-weight: 500; cursor: pointer; font-size: .875rem;
}
.btn-logout:hover { color: var(--destructive); }

.dev-credit {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: .7rem; color: var(--muted-foreground);
}
.dev-credit:hover { color: var(--primary); }

.mobile-header {
  display: none;
  height: 64px; background: var(--card); border-bottom: 1px solid var(--border);
  align-items: center; gap: 12px; padding: 0 16px; position: sticky; top: 0; z-index: 30;
}
.mobile-header .brand { color: var(--primary); font-weight: 700; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.hamburger { background: none; border: none; cursor: pointer; padding: 8px; color: var(--muted-foreground); }

.main-content { flex: 1; margin-left: 256px; padding: 32px; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); width: 280px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 16px; }
  .mobile-header { display: flex; }
  .overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
  .overlay.open { display: block; }
}

/* ---------- Common components ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: 1.9rem; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.page-subtitle { color: var(--muted-foreground); margin: 4px 0 0; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--muted); border-radius: var(--radius) var(--radius) 0 0; }
.card-title { font-weight: 600; font-size: 1.05rem; margin: 0; }
.card-body { padding: 20px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1000px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 640px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { padding: 18px 20px; }
.stat-card .stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted-foreground); font-size: .85rem; font-weight: 500; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-card .stat-hint { font-size: .75rem; color: var(--muted-foreground); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 8px; font-weight: 500; font-size: .875rem;
  border: 1px solid transparent; cursor: pointer; background: var(--primary); color: white;
}
.btn:hover { background: var(--primary-dark); }
.btn-outline { background: white; border-color: var(--border); color: var(--foreground); }
.btn-outline:hover { background: var(--muted); }
.btn-ghost { background: transparent; border: none; color: var(--muted-foreground); }
.btn-ghost:hover { color: var(--primary); }
.btn-danger { background: var(--destructive); }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .7rem; font-weight: 700; text-transform: uppercase; padding: 3px 10px; border-radius: 999px; }
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-green { background: var(--emerald-light); color: var(--emerald); }
.badge-slate { background: var(--muted); color: var(--muted-foreground); }
.badge-red { background: var(--destructive-light); color: var(--destructive); }

.avatar { border-radius: 999px; overflow: hidden; background: var(--muted); display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--muted-foreground); border: 1px solid var(--border); flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.divide-list > * { border-bottom: 1px solid var(--border); }
.divide-list > *:last-child { border-bottom: none; }

.list-row { padding: 16px; display: flex; align-items: center; gap: 16px; }
.list-row:hover { background: var(--muted); }

.empty-state { padding: 48px 24px; text-align: center; color: var(--muted-foreground); }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: .9rem; background: white; font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.form-control.field-invalid { border-color: var(--destructive); background: var(--destructive-light); }
.form-control.field-invalid:focus { box-shadow: 0 0 0 3px var(--destructive-light); }
.field-error-msg { color: var(--destructive); font-size: .75rem; margin-top: 4px; }

.alert { padding: 14px 16px; border-radius: 8px; border-left: 4px solid var(--destructive); background: var(--destructive-light); color: var(--destructive); margin-bottom: 20px; }
.alert strong { display: block; margin-bottom: 2px; }

.flash-success { padding: 10px 16px; border-radius: 8px; background: var(--emerald-light); color: var(--emerald); margin-bottom: 16px; font-weight: 500; font-size: .875rem; }

/* Modal */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 100; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal { background: white; border-radius: 12px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; padding: 24px; }
.modal h3 { margin-top: 0; }
.modal-close { position: absolute; top: 16px; right: 16px; }

.search-bar { display: flex; gap: 8px; padding: 16px; border-bottom: 1px solid var(--border); background: var(--muted); }
.search-input-wrap { position: relative; flex: 1; max-width: 420px; }
.search-input-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-foreground); width: 16px; height: 16px; }
.search-input-wrap input { padding-left: 36px; }

.filters-bar { display: flex; flex-wrap: wrap; gap: 12px; padding: 16px; border-bottom: 1px solid var(--border); background: var(--muted); align-items: center; }

.chip-link { color: var(--primary); font-weight: 500; font-size: .875rem; }
.chip-link:hover { text-decoration: underline; }

.icon { width: 18px; height: 18px; vertical-align: -3px; }

.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.photo-thumb .delete-btn {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 999px;
  background: var(--destructive); color: white; border: none; display: flex; align-items: center;
  justify-content: center; cursor: pointer; font-size: 12px;
}
.photo-empty { height: 120px; border: 2px dashed var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: .85rem; }
.upload-label { cursor: pointer; font-size: .75rem; font-weight: 500; color: var(--primary); display: flex; align-items: center; gap: 4px; }

.two-col { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 32px; }
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

.mini-calendar { padding: 16px; }
.mini-calendar table { border-collapse: collapse; width: 100%; }
.mini-calendar th { font-size: .7rem; color: var(--muted-foreground); padding: 4px; font-weight: 500; }
.mini-calendar td { text-align: center; padding: 2px; }
.mini-calendar a { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; font-size: .85rem; }
.mini-calendar a:hover { background: var(--muted); }
.mini-calendar a.cal-available { background: var(--emerald-light); color: var(--emerald); }
.mini-calendar a.cal-full { background: var(--blue-light); color: var(--blue); }
.mini-calendar a.cal-mixed { background: var(--amber-light); color: var(--amber); }
.mini-calendar a.selected { background: var(--primary); color: white; font-weight: 600; }
.mini-calendar a.today:not(.selected) { border: 1px solid var(--primary); }
.mini-calendar .muted { color: #cbd5e1; }
.cal-legend { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; color: var(--muted-foreground); }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 600; text-transform: capitalize; }

.month-switch { display: flex; align-items: center; gap: 4px; background: white; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.month-switch .month-label { width: 130px; text-align: center; font-weight: 500; font-size: .9rem; text-transform: capitalize; }

.login-wrap { min-height: 100vh; display: flex; }
.login-left { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; background: white; }
.login-box { width: 100%; max-width: 380px; }
.login-logo { width: 48px; height: 48px; border-radius: 14px; background: var(--primary); display: flex; align-items: center; justify-content: center; margin: 0 auto; box-shadow: 0 6px 16px rgba(13,148,136,.35); }
.login-right { flex: 1; background: var(--primary-light); display: none; align-items: center; justify-content: center; text-align: center; padding: 48px; }
@media (min-width: 1024px) { .login-right { display: flex; } }

.amber-box { background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 16px 18px; color: #78350f; }

canvas#financeChart { max-height: 320px; }
