:root {
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --sidebar-bg: #1a2332;
  --sidebar-text: #b8c2d0;
  --primary: #2f6feb;
  --text: #1f2937;
  --muted: #6b7280;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #d97706;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.layout { display: flex; min-height: 100vh; }

/* Barra superior mobile y bottom nav, ocultas en desktop */
.topbar-mobile { display: none; }
.bottom-nav { display: none; }
.sidebar-overlay { display: none; }

.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
}
.sidebar-brand { font-size: 1.1rem; font-weight: 700; color: white; padding: 0 20px 20px; }
.sidebar nav { display: flex; flex-direction: column; flex: 1; }
.sidebar nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 12px 20px;
  font-size: 0.95rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: white; }
.sidebar-user { padding: 0 20px 8px; font-size: 0.85rem; color: var(--sidebar-text); }
.logout-form { padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.1); }
.btn-logout {
  background: none; border: none; color: #f87171; cursor: pointer;
  padding: 10px 20px; font-size: 0.85rem; width: 100%; text-align: left;
}

.content { flex: 1; padding: 30px; max-width: 1400px; }

h1 { font-size: 1.6rem; margin: 0 0 20px; }
h2 { font-size: 1.2rem; margin: 30px 0 12px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  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); }

.metric-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 18px; }
.metric-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.metric-value { font-size: 1.5rem; font-weight: 700; }
.metric-value.green { color: var(--green); }
.metric-value.red { color: var(--red); }
.metric-value.orange { color: var(--orange); }

table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 10px; overflow: hidden; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { background: #f9fafb; font-weight: 600; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; }
tr:hover td { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-en_curso { background: #dbeafe; color: #1e40af; }
.badge-finalizada { background: #dcfce7; color: #166534; }
.badge-cancelada { background: #fee2e2; color: #991b1b; }

.progress-bar { background: #e5e7eb; border-radius: 999px; height: 8px; width: 100%; overflow: hidden; }
.progress-bar-fill { background: var(--green); height: 100%; }

.btn {
  display: inline-block; background: var(--primary); color: white; border: none;
  padding: 10px 18px; border-radius: 8px; font-size: 0.9rem; text-decoration: none;
  cursor: pointer; font-weight: 600;
}
.btn:hover { background: #2558c4; }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }

.actions-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }

form.form-card { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.form-row input, .form-row select, .form-row textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; font-family: inherit;
}
.form-row-inline { display: flex; gap: 14px; }
.form-row-inline .form-row { flex: 1; }

.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item { padding: 10px 14px; border-radius: 8px; font-size: 0.88rem; }
.alert-item.pending { background: #fee2e2; color: #991b1b; }
.alert-item.excedido { background: #ffedd5; color: #9a3412; }
.alert-item.architect { background: #fef9c3; color: #854d0e; }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg);
}
.login-card { background: white; padding: 40px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); width: 100%; max-width: 380px; }
.login-card h1 { text-align: center; }
.error-msg { background: #fee2e2; color: #991b1b; padding: 10px; border-radius: 8px; font-size: 0.85rem; margin-bottom: 10px; }

a.link { color: var(--primary); text-decoration: none; font-size: 0.88rem; }
.muted { color: var(--muted); }

/* ================= MOBILE ================= */
@media (max-width: 900px) {
  .layout { flex-direction: column; }

  /* Barra superior con botón hamburguesa */
  .topbar-mobile {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--sidebar-bg);
    color: white;
    padding: 14px 16px;
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .topbar-title { font-weight: 700; font-size: 1rem; }
  .hamburger {
    background: none; border: none; padding: 6px; cursor: pointer;
    display: flex; flex-direction: column; gap: 4px; justify-content: center;
  }
  .hamburger span { width: 22px; height: 2px; background: white; border-radius: 2px; display: block; }

  /* Sidebar se convierte en panel deslizable oculto por defecto */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 250px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar nav a { padding: 16px 20px; font-size: 1rem; }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  /* Barra inferior de navegación rápida, siempre visible */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--sidebar-bg);
    z-index: 30;
    padding: 6px 0 max(6px, env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
  }
  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 1.2rem;
    padding: 6px 0;
  }
  .bottom-nav a span { font-size: 0.65rem; }
  .bottom-nav a:active { color: white; }

  .content { padding: 16px 16px 80px; } /* espacio abajo para no tapar contenido con la bottom nav */
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }

  table { display: block; overflow-x: auto; white-space: nowrap; }

  .actions-bar { flex-direction: column; align-items: stretch; }
  .actions-bar .btn, .actions-bar a.btn { text-align: center; }
}

@media (max-width: 480px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 1.3rem; }
  .metric-value { font-size: 1.3rem; }
  .form-row-inline { flex-direction: column; gap: 14px; }
}
