:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --violet: #7c3aed;
  --teal: #0891b2;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --radius: 12px;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.hidden { display: none !important; }

/* ===== LOGIN ===== */
.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a, #2563eb);
  padding: 16px;
}
.login-card {
  background: #fff; padding: 32px 28px; border-radius: 16px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-brand { font-size: 24px; font-weight: 800; text-align: center; }
.login-sub { text-align: center; color: var(--muted); margin: 4px 0 20px; }

/* ===== LAYOUT ===== */
.sidebar {
  position: fixed; top: 0; left: 0; width: 240px; height: 100vh;
  background: var(--sidebar); color: #fff; padding: 16px 12px;
  display: flex; flex-direction: column; z-index: 10;
  transition: transform 0.3s ease;
}
.brand { font-size: 18px; font-weight: 800; padding: 8px 10px 14px; border-bottom: 1px solid #1e293b; }
nav { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  background: transparent; color: #cbd5e1; border: none; text-align: left;
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
  transition: background .15s, color .15s;
  min-height: 40px; display: flex; align-items: center;
}
.nav-btn:hover { background: var(--sidebar-hover); color: #fff; }
.nav-btn.active { background: var(--primary); color: #fff; }
.sidebar-footer {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between;
  padding-top: 14px; border-top: 1px solid #1e293b; font-size: 13px; color: #94a3b8;
}
.sidebar-footer button {
  background: #1e293b; color: #fff; border: none; padding: 6px 10px; border-radius: 6px; cursor: pointer;
}

.main { margin-left: 240px; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; background: #fff; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); z-index: 5;
}
.topbar h2 { margin: 0; font-size: 18px; }
#content { padding: 20px; }

/* ===== MOBILE NAVIGATION ===== */
.mobile-header {
  position: fixed; top: 0; left: 0; right: 0; height: 56px;
  background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 12px;
  z-index: 100; justify-content: space-between;
}
.mobile-menu-toggle {
  background: var(--sidebar); color: #fff; border: none; padding: 8px;
  border-radius: 8px; cursor: pointer; font-size: 20px;
  display: none;
}
.mobile-nav {
  position: fixed; left: 0; top: 56px; width: 80%; max-width: 280px;
  height: calc(100vh - 56px); background: var(--sidebar); color: #fff;
  padding: 16px; transform: translateX(-100%); transition: transform 0.3s ease;
  z-index: 99; overflow-y: auto;
}
.mobile-nav.active { transform: translateX(0); }
.mobile-nav .nav-btn {
  color: #cbd5e1; width: 100%; text-align: left; margin-bottom: 4px;
}
.mobile-nav .nav-btn.active { background: var(--primary); }
.mobile-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 98;
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.mobile-overlay.active { opacity: 1; pointer-events: auto; }

/* ===== CARDS ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.stat-card.stat-blue { border-left-color: var(--primary); }
.stat-card.stat-green { border-left-color: var(--green); }
.stat-card.stat-red { border-left-color: var(--red); }
.stat-card.stat-violet { border-left-color: var(--violet); }
.stat-card.stat-teal { border-left-color: var(--teal); }
.stat-value { font-size: 24px; font-weight: 800; }
.stat-label { color: var(--muted); margin-top: 4px; font-size: 13px; }
.stat-sub { color: var(--muted); font-size: 11px; margin-top: 6px; }

/* ===== PANELS ===== */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 20px; }
.panel {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 20px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h3 { margin: 0; font-size: 15px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item strong { display: block; }
.list-item .muted { color: var(--muted); font-size: 12px; }
.amount { font-weight: 700; text-align: right; }
.amount.red { color: var(--red); }
.amount.green { color: var(--green); }

/* ===== TABLES ===== */
.filter-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-btn {
  background: #fff; border: 1px solid var(--border); padding: 6px 12px;
  border-radius: 999px; cursor: pointer; font-size: 12px;
}
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 700; letter-spacing: .4px; }
tr:hover td { background: #f8fafc; }
.actions { white-space: nowrap; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; }
.btn-icon.danger { filter: grayscale(.2); }
.empty { text-align: center; padding: 30px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 11px; }

/* ===== BADGES ===== */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.badge.available { background: #dcfce7; color: #166534; }
.badge.occupied { background: #dbeafe; color: #1e40af; }
.badge.maintenance { background: #fef3c7; color: #92400e; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.expired { background: #e2e8f0; color: #475569; }
.badge.terminated { background: #fee2e2; color: #991b1b; }
.badge.due { background: #fee2e2; color: #991b1b; }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--primary); color: #fff; border: none; padding: 9px 16px;
  border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary.full { width: 100%; }
.btn {
  background: #e2e8f0; color: var(--text); border: none; padding: 9px 16px;
  border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.btn:hover { background: #cbd5e1; }

/* ===== MODAL ===== */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#modal {
  background: #fff; border-radius: 14px; width: 460px; max-width: 92vw;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 25px 70px rgba(0,0,0,.3);
}
.modal-form { padding: 22px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 13px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 18px;
  border-radius: 10px; background: #0f172a; color: #fff; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); opacity: 0; transform: translateY(20px);
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-ok { background: var(--green); }
.toast.toast-error { background: var(--red); }

/* ===== UTILS ===== */
code { background: #e2e8f0; padding: 2px 6px; border-radius: 4px; }
.error-box { background: #fee2e2; color: #991b1b; padding: 14px; border-radius: 8px; }

/* ===== RESPONSIVE: TABLET (769px - 1024px) ===== */
@media (max-width: 1024px) and (min-width: 769px) {
  .sidebar { width: 220px; }
  .main { margin-left: 220px; }
  .cards { grid-template-columns: repeat(3, 1fr); }
}

/* ===== RESPONSIVE: MOBILE (max 768px) ===== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .topbar { padding: 10px 12px; }
  .topbar h2 { font-size: 16px; }
  #content { padding: 12px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 18px; }
  .grid-2 { grid-template-columns: 1fr; gap: 12px; }
  .panel { padding: 14px; }
  .login-card { padding: 28px 20px; }
  .login-brand { font-size: 22px; }
  .mobile-menu-toggle { display: inline-block; }
  .mobile-nav { display: block; }
  .modal { width: 95vw; max-width: 95vw; }
  .modal-form { padding: 16px; }
  table { font-size: 13px; }
  th, td { padding: 8px 6px; }
  .filter-bar { gap: 6px; }
  .filter-btn { padding: 5px 10px; font-size: 11px; }
  .toast { bottom: 16px; right: 16px; left: 16px; max-width: none; }
}

/* ===== RESPONSIVE: SMALL MOBILE (max 480px) ===== */
@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .stat-value { font-size: 20px; }
  .topbar { padding: 8px 10px; }
  .topbar h2 { font-size: 15px; }
  #content { padding: 10px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 500px; }
  .modal { width: 100%; max-width: 100%; border-radius: 12px 12px 0 0; }
  #modal-backdrop { align-items: flex-end; }
  .btn-primary, .btn { padding: 10px 14px; font-size: 14px; min-height: 44px; }
  .nav-btn { padding: 12px 14px; font-size: 15px; }
}

/* ===== RESPONSIVE: LANDSCAPE MOBILE ===== */
@media (max-height: 500px) and (orientation: landscape) {
  .login-card { padding: 20px 24px; }
  .login-brand { font-size: 20px; }
  .login-sub { margin-bottom: 12px; }
  .sidebar { padding: 10px 12px; }
  .brand { padding: 6px 8px 10px; }
}
