:root {
  --mo-primary: #1a2e4a;
  --mo-primary-dark: #0f1e33;
  --mo-accent: #f97316;
  --mo-accent-d97: #d97757;
  --mo-accent-light: #fff7ed;
  --mo-sidebar-w: 240px;
  /* Dark mode tokens (default: light) */
  --mo-bg: #f1f5f9;
  --mo-surface: #ffffff;
  --mo-surface2: #f8fafc;
  --mo-border: #e2e8f0;
  --mo-border2: #f1f5f9;
  --mo-text: #1e293b;
  --mo-text-m: #64748b;
  --mo-text-d: #94a3b8;
  --mo-topbar-bg: #ffffff;
  --mo-table-th: #f8fafc;
  --mo-table-hover: #f8fafc;
  --mo-input-bg: #ffffff;
}
[data-theme="dark"] {
  --mo-bg: #0d0d0d;
  --mo-surface: #161616;
  --mo-surface2: #1e1e1e;
  --mo-border: rgba(255,255,255,.09);
  --mo-border2: rgba(255,255,255,.05);
  --mo-text: #e8e5e0;
  --mo-text-m: #888880;
  --mo-text-d: #555550;
  --mo-topbar-bg: #111111;
  --mo-table-th: #1a1a1a;
  --mo-table-hover: rgba(255,255,255,.03);
  --mo-input-bg: rgba(255,255,255,.05);
}

body { background: var(--mo-bg); color: var(--mo-text); font-family: 'Segoe UI', system-ui, sans-serif; transition: background .2s, color .2s; }

/* ── SIDEBAR ── */
.mo-sidebar {
  width: var(--mo-sidebar-w);
  min-height: 100vh;
  background: var(--mo-primary-dark);
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform 0.3s;
}
.mo-sidebar .brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  color: white;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.mo-sidebar .brand span { color: var(--mo-accent); }
.mo-sidebar .user-info {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.mo-sidebar .user-name { color: #e2e8f0; font-size: 0.88rem; font-weight: 600; }
.mo-sidebar .user-role { color: #64748b; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.mo-sidebar .nav-section-label {
  color: #475569;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 16px 20px 6px;
}
.mo-sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: #94a3b8;
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  border-radius: 0;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.mo-sidebar .nav-link:hover { color: #e2e8f0; background: rgba(255,255,255,0.05); }
.mo-sidebar .nav-link.active { color: white; background: rgba(249,115,22,0.12); border-left-color: var(--mo-accent); }
.mo-sidebar .nav-link i { font-size: 1rem; width: 18px; text-align: center; }
.mo-sidebar .logout-btn {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.mo-sidebar .logout-btn a {
  color: #64748b;
  font-size: 0.84rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: color 0.15s;
}
.mo-sidebar .logout-btn a:hover { color: #ef4444; }

/* ── MAIN CONTENT ── */
.mo-main {
  margin-left: var(--mo-sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.mo-topbar {
  background: var(--mo-topbar-bg);
  border-bottom: 1px solid var(--mo-border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.mo-topbar h1 { font-size: 1.1rem; font-weight: 700; color: var(--mo-primary); margin: 0; }
[data-theme="dark"] .mo-topbar h1 { color: var(--mo-text); }
.mo-content { padding: 28px; flex: 1; }
.mo-topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-theme-btn { background: transparent; border: 1px solid var(--mo-border); color: var(--mo-text-m); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: .9rem; display: flex; align-items: center; justify-content: center; transition: all .15s; }
.topbar-theme-btn:hover { background: var(--mo-surface2); color: var(--mo-text); }

/* ── CARDS ── */
.mo-kpi {
  background: var(--mo-surface);
  border: 1px solid var(--mo-border);
  border-radius: 12px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.mo-kpi .kpi-label { font-size: 0.78rem; font-weight: 600; color: var(--mo-text-m); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.mo-kpi .kpi-value { font-size: 1.7rem; font-weight: 800; color: var(--mo-text); line-height: 1; }
.mo-kpi .kpi-sub { font-size: 0.8rem; color: var(--mo-text-d); margin-top: 6px; }
.mo-kpi .kpi-icon {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.mo-kpi.orange .kpi-icon { background: rgba(249,115,22,.12); color: var(--mo-accent); }
.mo-kpi.blue .kpi-icon { background: rgba(14,165,233,.1); color: #0ea5e9; }
.mo-kpi.green .kpi-icon { background: rgba(34,197,94,.1); color: #22c55e; }
.mo-kpi.amber .kpi-icon { background: rgba(245,158,11,.1); color: #f59e0b; }
.mo-kpi.red .kpi-icon { background: rgba(239,68,68,.1); color: #ef4444; }

/* ── OBRA CARD ── */
.obra-card {
  background: var(--mo-surface);
  border: 1px solid var(--mo-border);
  border-radius: 12px;
  padding: 20px;
  transition: box-shadow 0.2s, transform 0.15s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.obra-card:hover { box-shadow: 0 8px 30px rgba(0,0,0,0.1); transform: translateY(-2px); color: inherit; }
.obra-card .obra-name { font-size: 1rem; font-weight: 700; color: var(--mo-text); margin-bottom: 4px; }
.obra-card .obra-cliente { font-size: 0.82rem; color: var(--mo-text-m); margin-bottom: 14px; }
.obra-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.obra-badge.activa { background: #dcfce7; color: #166534; }
.obra-badge.pausada { background: #fef9c3; color: #854d0e; }
.obra-badge.terminada { background: #dbeafe; color: #1e40af; }
.obra-badge.archivada { background: rgba(100,116,139,.15); color: #64748b; }

/* ── PROGRESS ── */
.mo-progress { height: 8px; border-radius: 4px; background: var(--mo-border); overflow: hidden; }
.mo-progress-bar { height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.mo-progress-bar.orange { background: var(--mo-accent); }
.mo-progress-bar.green { background: #22c55e; }
.mo-progress-bar.blue { background: #0ea5e9; }
.mo-progress-bar.red { background: #ef4444; }

/* ── TABLES ── */
.mo-table { background: var(--mo-surface); border-radius: 12px; border: 1px solid var(--mo-border); overflow: hidden; }
.mo-table table { width: 100%; border-collapse: collapse; }
.mo-table th { background: var(--mo-table-th); color: var(--mo-text-m); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; padding: 12px 16px; border-bottom: 1px solid var(--mo-border); }
.mo-table td { padding: 12px 16px; border-bottom: 1px solid var(--mo-border2); font-size: 0.88rem; color: var(--mo-text); vertical-align: middle; }
.mo-table tr:last-child td { border-bottom: none; }
.mo-table tr:hover td { background: var(--mo-table-hover); }

/* ── FORMS ── */
.mo-form-card { background: var(--mo-surface); border: 1px solid var(--mo-border); border-radius: 12px; padding: 28px; }
.mo-label { font-size: 0.82rem; font-weight: 600; color: var(--mo-text-m); margin-bottom: 5px; }
.mo-form-section { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--mo-accent); margin: 24px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--mo-border); }
.form-control, .form-select { background-color: var(--mo-input-bg) !important; border-color: var(--mo-border) !important; color: var(--mo-text) !important; }
.form-control:focus, .form-select:focus { border-color: var(--mo-accent) !important; box-shadow: 0 0 0 3px rgba(249,115,22,.15) !important; }
.form-control::placeholder { color: var(--mo-text-d) !important; }
[data-theme="dark"] .bg-light { background: var(--mo-surface2) !important; }

/* ── TABS ── */
.mo-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--mo-border); margin-bottom: 24px; }
.mo-tab { padding: 10px 20px; font-size: 0.88rem; font-weight: 600; color: var(--mo-text-m); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s; }
.mo-tab:hover { color: var(--mo-text); }
.mo-tab.active { color: var(--mo-accent); border-bottom-color: var(--mo-accent); }

/* ── BUTTONS ── */
/* CRITICAL FIX: Use !important on color to prevent Bootstrap .btn hover override */
.btn-mo {
  background: var(--mo-accent);
  color: white !important;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-mo:hover,
.btn-mo:focus {
  background: #ea6c0d;
  color: white !important;
  opacity: 1;
  box-shadow: 0 4px 12px rgba(249,115,22,.3);
  text-decoration: none;
}
.btn-mo.btn-sm { padding: 6px 12px; font-size: 0.82rem; }

.btn-danger-sm { background: transparent; border: 1px solid rgba(239,68,68,.3); color: #ef4444; padding: 3px 9px; border-radius: 6px; font-size: .75rem; cursor: pointer; transition: all .15s; }
.btn-danger-sm:hover { background: rgba(239,68,68,.1); }
.btn-edit-sm { background: transparent; border: 1px solid var(--mo-border); color: var(--mo-text-m); padding: 3px 9px; border-radius: 6px; font-size: .75rem; cursor: pointer; transition: all .15s; }
.btn-edit-sm:hover { background: var(--mo-surface2); color: var(--mo-text); }

/* ── ROLE BADGES ── */
.role-badge {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.role-badge.director { background: rgba(217,119,87,.12); color: #d97757; }
.role-badge.colaborador { background: rgba(14,165,233,.1); color: #0ea5e9; }
.role-badge.admin { background: rgba(168,85,247,.1); color: #c084fc; }

/* ── AUDIT LOG ── */
.audit-row { font-size: .8rem; border-bottom: 1px solid var(--mo-border2); padding: 8px 0; }
.audit-accion { font-weight: 600; color: var(--mo-text); }
.audit-detalle { color: var(--mo-text-m); }
.audit-time { color: var(--mo-text-d); font-size: .72rem; }

/* ── AUTH PAGES ── */
.auth-page { min-height: 100vh; background: linear-gradient(135deg, #0f1e33 0%, #1a3558 100%); display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: white; border-radius: 20px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.auth-brand { text-align: center; font-size: 1.5rem; font-weight: 800; color: var(--mo-primary); margin-bottom: 8px; }
.auth-brand span { color: var(--mo-accent); }
.auth-sub { text-align: center; color: #64748b; font-size: 0.88rem; margin-bottom: 28px; }

/* ── PHOTO GRID ── */
.foto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.foto-item { border-radius: 10px; overflow: hidden; aspect-ratio: 4/3; background: var(--mo-surface2); position: relative; }
.foto-item img { width: 100%; height: 100%; object-fit: cover; }
.foto-del-btn { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.6); color: white; border: none; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: .8rem; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .15s; }
.foto-item:hover .foto-del-btn { opacity: 1; }

/* ── PORTAL ── */
.portal-hero { background: linear-gradient(135deg, #0f1e33, #1a3558); color: white; padding: 48px 20px; text-align: center; }

/* ── ALERTS ── */
.mo-alert { padding: 12px 16px; border-radius: 8px; font-size: 0.88rem; margin-bottom: 16px; }
.mo-alert.error { background: rgba(220,38,38,.08); color: #ef4444; border: 1px solid rgba(220,38,38,.2); }
.mo-alert.success { background: rgba(34,197,94,.08); color: #22c55e; border: 1px solid rgba(34,197,94,.2); }
.mo-alert.warning { background: rgba(245,158,11,.08); color: #f59e0b; border: 1px solid rgba(245,158,11,.2); }

/* ── HAMBURGER (mobile) ── */
.mo-hamburger { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--mo-text); }

/* ── MODALS (dark mode) ── */
[data-theme="dark"] .modal-content { background: var(--mo-surface); border-color: var(--mo-border); }
[data-theme="dark"] .modal-header { border-bottom-color: var(--mo-border); }
[data-theme="dark"] .modal-footer { border-top-color: var(--mo-border); }
[data-theme="dark"] .modal-title { color: var(--mo-text); }
[data-theme="dark"] .btn-close { filter: invert(1); }

@media (max-width: 768px) {
  .mo-sidebar { transform: translateX(-100%); }
  .mo-sidebar.open { transform: translateX(0); }
  .mo-main { margin-left: 0; }
  .mo-topbar { padding: 12px 16px; }
  .mo-content { padding: 16px; }
  .mo-hamburger { display: block; }
  .mo-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; }
  .mo-overlay.open { display: block; }
}
