:root {
  --caal-navy: #0b2b4c;
  --caal-navy-2: #123f6d;
  --caal-blue: #1768d1;
  --caal-blue-soft: #eaf2ff;
  --caal-gold: #f4a300;
  --caal-gold-soft: #fff4d7;
  --page-bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #172033;
  --muted: #667085;
  --border: #dfe6ef;
  --success: #16865a;
  --success-soft: #e7f7f0;
  --danger: #c83b3b;
  --danger-soft: #ffeded;
  --warning: #b96b00;
  --warning-soft: #fff4dc;
  --secondary: #667085;
  --sidebar-width: 272px;
  --topbar-height: 76px;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --shadow-sm: 0 5px 18px rgba(15, 35, 58, .07);
  --shadow-md: 0 14px 34px rgba(15, 35, 58, .11);
  --shadow-lg: 0 30px 70px rgba(8, 30, 54, .22);
}

* { box-sizing: border-box; }
html { min-height: 100%; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); }
body { min-height: 100vh; margin: 0; background: var(--page-bg); color: var(--ink); line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
a { color: var(--caal-blue); text-decoration: none; }
a:hover { text-decoration: none; }
svg { display: block; }

/* App shell */
.sidebar-toggle { position: fixed; opacity: 0; pointer-events: none; }
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  color: #fff;
  background:
    radial-gradient(circle at 20% 88%, rgba(244, 163, 0, .14), transparent 22%),
    linear-gradient(180deg, #0b2b4c 0%, #09233d 58%, #071b30 100%);
  box-shadow: 10px 0 35px rgba(7, 27, 48, .13);
}
.sidebar-brand { min-height: 104px; padding: 22px 20px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.sidebar-brand a { display: block; width: 218px; }
.sidebar-brand img { width: 100%; height: auto; }
.sidebar-close { display: none; width: 34px; height: 34px; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.18); border-radius: 10px; font-size: 26px; cursor: pointer; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 14px 24px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.nav-section { margin-bottom: 18px; }
.nav-section-title { padding: 6px 12px 8px; color: rgba(255,255,255,.52); font-size: .7rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sidebar-link { min-height: 46px; margin: 3px 0; padding: 10px 12px; display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,.84); border-radius: 12px; font-size: .93rem; font-weight: 650; transition: background .18s ease, color .18s ease, transform .18s ease; }
.sidebar-link svg { width: 21px; height: 21px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-link:hover { color: #fff; background: rgba(255,255,255,.08); transform: translateX(2px); }
.sidebar-link.active { color: #fff; background: linear-gradient(135deg, #1768d1, #1559b0); box-shadow: 0 9px 22px rgba(23, 104, 209, .28); }
.sidebar-link.active::before { content: ""; width: 4px; height: 22px; margin-left: -12px; border-radius: 0 4px 4px 0; background: var(--caal-gold); }
.sidebar-profile { margin: 0 14px 16px; padding: 13px; display: grid; grid-template-columns: 42px 1fr 34px; align-items: center; gap: 10px; border: 1px solid rgba(255,255,255,.11); border-radius: 15px; background: rgba(255,255,255,.06); }
.profile-avatar { width: 42px; height: 42px; display: grid; place-items: center; color: var(--caal-navy); background: linear-gradient(135deg, #fff, #e7eef6); border-radius: 50%; font-weight: 900; }
.profile-copy { min-width: 0; }
.profile-copy strong, .profile-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-copy strong { font-size: .86rem; }
.profile-copy span { color: rgba(255,255,255,.6); font-size: .72rem; }
.profile-logout { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; color: rgba(255,255,255,.78); border: 0; border-radius: 9px; background: transparent; cursor: pointer; }
.profile-logout:hover { color: #fff; background: rgba(255,255,255,.1); }
.profile-logout svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-backdrop { display: none; }

.app-main { min-height: 100vh; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 35; min-height: var(--topbar-height); padding: 0 30px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: rgba(255,255,255,.94); border-bottom: 1px solid rgba(218, 226, 236, .9); box-shadow: 0 3px 16px rgba(15, 35, 58, .04); backdrop-filter: blur(12px); }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }
.menu-button { display: none; width: 42px; height: 42px; place-items: center; color: var(--caal-navy); border: 1px solid var(--border); border-radius: 12px; background: #fff; cursor: pointer; }
.menu-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.topbar-title { color: var(--caal-navy); font-size: .98rem; font-weight: 850; }
.topbar-subtitle { color: var(--muted); font-size: .76rem; }
.status-chip { padding: 7px 11px; display: flex; align-items: center; gap: 7px; color: #116845; border: 1px solid #cfeade; border-radius: 999px; background: #f2fbf7; font-size: .76rem; font-weight: 750; }
.status-chip span { width: 8px; height: 8px; border-radius: 50%; background: #20a86e; box-shadow: 0 0 0 4px rgba(32,168,110,.12); }
.topbar-user-copy { padding-left: 13px; border-left: 1px solid var(--border); text-align: right; }
.topbar-user-copy strong, .topbar-user-copy span { display: block; }
.topbar-user-copy strong { color: var(--caal-navy); font-size: .83rem; }
.topbar-user-copy span { color: var(--muted); font-size: .72rem; }
.page-content { width: 100%; max-width: 1640px; margin: 0 auto; padding: 28px 30px 38px; flex: 1; }
.app-footer { padding: 17px 30px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: #6b7788; border-top: 1px solid var(--border); background: #fff; font-size: .76rem; }
.app-footer span:first-child { color: var(--caal-navy); font-weight: 800; }

/* Headings and utilities */
h1, h2, h3, h4, p { margin-top: 0; }
.h3 { font-size: clamp(1.55rem, 2vw, 2rem); line-height: 1.18; }
.h4 { font-size: 1.3rem; }
.h5 { font-size: 1.08rem; }
.display-6 { font-size: clamp(2rem, 3vw, 2.65rem); line-height: 1; }
.fw-bold { font-weight: 800; }
.small { font-size: .84rem; }
.text-primary { color: var(--caal-blue); }
.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.text-end { text-align: right; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .25rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.me-3 { margin-right: 1rem; }
.p-3 { padding: 1rem; }
.py-3 { padding-top: 1rem; padding-bottom: 1rem; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.w-100 { width: 100%; }
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-content-between { justify-content: space-between; }
.justify-content-center { justify-content: center; }
.align-items-center { align-items: center; }
.align-items-end { align-items: flex-end; }
.gap-2 { gap: .5rem; }
.container-fluid { width: 100%; }
.page-narrow { max-width: 920px; margin: 0 auto; }
.page-wide { max-width: 1320px; margin: 0 auto; }

.row { display: flex; flex-wrap: wrap; margin-left: -.55rem; margin-right: -.55rem; }
.row > * { width: 100%; padding-left: .55rem; padding-right: .55rem; }
.g-2 { row-gap: .7rem; }
.g-3 { row-gap: 1.1rem; }
.g-4 { row-gap: 1.5rem; }
.col-auto { width: auto; }

/* Cards */
.card { position: relative; overflow: hidden; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-body { padding: 1.25rem; }
.card-header { min-height: 54px; padding: .95rem 1.25rem; display: flex; align-items: center; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, #fbfdff, #f7f9fc); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.border-0 { border: 0; }
.card-link { display: block; color: var(--ink); transition: transform .18s ease, box-shadow .18s ease; }
.card-link:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card { min-height: 132px; border: 0; box-shadow: var(--shadow-sm); }
.stat-card::after { content: ""; position: absolute; right: -24px; bottom: -34px; width: 120px; height: 120px; border-radius: 50%; background: rgba(23,104,209,.055); }
.warning-card::after { background: rgba(244,163,0,.08); }
.dispatch-card::after { background: rgba(22,134,90,.07); }
.info-card { border-left: 4px solid var(--caal-blue); }

/* Buttons */
.btn { min-height: 42px; padding: .65rem .95rem; display: inline-flex; align-items: center; justify-content: center; gap: .48rem; color: var(--ink); border: 1px solid transparent; border-radius: 11px; background: #fff; font-size: .9rem; font-weight: 750; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, background .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-sm { min-height: 34px; padding: .42rem .7rem; border-radius: 9px; font-size: .8rem; }
.btn-primary { color: #fff; background: linear-gradient(135deg, #1768d1, #1557aa); border-color: #1768d1; box-shadow: 0 8px 18px rgba(23,104,209,.18); }
.btn-primary:hover { box-shadow: 0 10px 24px rgba(23,104,209,.26); }
.btn-success { color: #fff; background: linear-gradient(135deg, #1d9a69, #12734d); border-color: #16865a; box-shadow: 0 8px 18px rgba(22,134,90,.18); }
.btn-outline-primary { color: var(--caal-blue); border-color: #9cc2ee; background: #f8fbff; }
.btn-outline-primary:hover { background: var(--caal-blue-soft); }
.btn-outline-secondary { color: #4e5968; border-color: #cbd4df; background: #fff; }
.btn-outline-secondary:hover { background: #f4f6f8; }
.btn-outline-light { color: #fff; border-color: rgba(255,255,255,.7); background: transparent; }
.btn-gold { color: #172033; background: linear-gradient(135deg, #ffc44b, #f4a300); border-color: #f4a300; box-shadow: 0 8px 18px rgba(244,163,0,.22); }

/* Forms */
.form-label { display: block; margin-bottom: .38rem; color: #344054; font-size: .86rem; font-weight: 750; }
.form-control, .form-select { width: 100%; min-height: 44px; padding: .66rem .76rem; color: var(--ink); border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; outline: none; transition: border-color .16s ease, box-shadow .16s ease; }
.form-control:hover, .form-select:hover { border-color: #aebdce; }
.form-control:focus, .form-select:focus { border-color: var(--caal-blue); box-shadow: 0 0 0 4px rgba(23,104,209,.12); }
textarea.form-control { min-height: 110px; resize: vertical; }
.form-check-input { width: 1.1rem; height: 1.1rem; accent-color: var(--caal-blue); }
.form-text { margin-top: .35rem; color: var(--muted); font-size: .8rem; }
.input-error { border-color: var(--danger); background: #fff8f8; }
.cantidad-linea[readonly] { background: var(--success-soft); color: #116845; font-weight: 800; }
.cantidad-despacho { min-width: 135px; }

/* Tables and lists */
.table-responsive { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .82rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { color: #485467; background: #f5f8fb; text-align: left; white-space: nowrap; font-size: .76rem; font-weight: 850; letter-spacing: .035em; text-transform: uppercase; }
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: #f8fbff; }
tbody tr:last-child td { border-bottom: 0; }
.table-sm th, .table-sm td { padding: .64rem .72rem; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: .28rem .62rem; color: #fff; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.text-bg-success { background: var(--success); }
.text-bg-danger { background: var(--danger); }
.text-bg-secondary { background: var(--secondary); }
.text-bg-warning { background: #d88900; }
.list-group-item { min-height: 51px; padding: .78rem 1.15rem; display: flex; align-items: center; color: var(--ink); border-bottom: 1px solid var(--border); transition: background .15s ease, padding .15s ease; }
.list-group-item:last-child { border-bottom: 0; }
.list-group-item:hover { padding-left: 1.3rem; background: #f7faff; }

/* Alerts */
.alert { margin-bottom: 1rem; padding: .86rem 1rem; color: #31526d; border: 1px solid #c9deef; border-radius: 12px; background: #edf7ff; box-shadow: 0 4px 12px rgba(15,35,58,.035); }
.alert-success { color: #146242; border-color: #bfe5d3; background: var(--success-soft); }
.alert-danger, .alert-error { color: #8f2828; border-color: #f2c1c1; background: var(--danger-soft); }
.alert-info { color: #31526d; border-color: #c9deef; background: #edf7ff; }

/* Dashboard */
.dashboard-hero { position: relative; min-height: 260px; margin-bottom: 22px; overflow: hidden; display: flex; align-items: stretch; color: #fff; border-radius: var(--radius-lg); background: var(--caal-navy); box-shadow: var(--shadow-md); }
.dashboard-hero::before { content: ""; position: absolute; inset: 0; background: url("../img/construction-hero.webp") center right / cover no-repeat; }
.dashboard-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(7,27,48,.98) 0%, rgba(11,43,76,.94) 35%, rgba(11,43,76,.62) 63%, rgba(11,43,76,.13) 100%); }
.hero-content { position: relative; z-index: 2; width: min(660px, 65%); padding: 38px 42px; display: flex; flex-direction: column; justify-content: center; }
.hero-kicker { margin-bottom: 9px; color: #ffd268; font-size: .76rem; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
.hero-title { margin-bottom: 9px; font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1; letter-spacing: -.035em; }
.hero-copy { max-width: 540px; margin-bottom: 22px; color: rgba(255,255,255,.78); font-size: 1rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-actions .btn-outline-light { background: rgba(255,255,255,.05); }
.page-heading { margin-bottom: 20px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
.page-heading-copy h1 { margin-bottom: 4px; }
.page-heading-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.metric-card { min-height: 132px; padding: 19px; display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: 14px; color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-sm); transition: transform .18s ease, box-shadow .18s ease; }
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.metric-icon { width: 48px; height: 48px; display: grid; place-items: center; color: var(--caal-blue); border-radius: 15px; background: var(--caal-blue-soft); }
.metric-card.green .metric-icon { color: var(--success); background: var(--success-soft); }
.metric-card.gold .metric-icon { color: var(--warning); background: var(--caal-gold-soft); }
.metric-card.red .metric-icon { color: var(--danger); background: var(--danger-soft); }
.metric-card.purple .metric-icon { color: #7152bd; background: #f0ebff; }
.metric-icon svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.metric-copy span, .metric-copy strong, .metric-copy small { display: block; }
.metric-copy span { color: var(--muted); font-size: .72rem; font-weight: 850; letter-spacing: .045em; text-transform: uppercase; }
.metric-copy strong { margin: 2px 0 3px; color: var(--caal-navy); font-size: 2rem; line-height: 1; }
.metric-copy small { color: #8791a1; font-size: .72rem; }
.quick-section { margin-bottom: 24px; }
.section-title { margin-bottom: 11px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title h2 { margin: 0; color: var(--caal-navy); font-size: 1.05rem; }
.section-title span { color: var(--muted); font-size: .78rem; }
.quick-actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.quick-action { min-height: 108px; padding: 15px; display: flex; align-items: center; gap: 13px; color: var(--ink); border: 1px solid var(--border); border-radius: 15px; background: #fff; box-shadow: 0 5px 16px rgba(15,35,58,.045); transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.quick-action:hover { transform: translateY(-2px); border-color: #aec9eb; box-shadow: var(--shadow-sm); }
.quick-action-icon { width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center; color: #fff; border-radius: 13px; background: linear-gradient(135deg, #1768d1, #1557aa); }
.quick-action.green .quick-action-icon { background: linear-gradient(135deg, #20a86e, #16865a); }
.quick-action.gold .quick-action-icon { color: #172033; background: linear-gradient(135deg, #ffc44b, #f4a300); }
.quick-action.purple .quick-action-icon { background: linear-gradient(135deg, #8065d8, #5e43b5); }
.quick-action.teal .quick-action-icon { background: linear-gradient(135deg, #15a2a2, #0c7e82); }
.quick-action-icon svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.quick-action strong, .quick-action span { display: block; }
.quick-action strong { color: var(--caal-navy); font-size: .88rem; }
.quick-action span { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(310px, .8fr) minmax(520px, 1.35fr); gap: 18px; }
.panel-title { display: flex; align-items: center; gap: 9px; }
.panel-title svg { width: 20px; height: 20px; color: var(--caal-blue); fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.work-code { min-width: 58px; padding: 4px 8px; color: var(--caal-navy); border-radius: 999px; background: #edf3fa; text-align: center; font-size: .72rem; font-weight: 800; }
.movement-material { max-width: 350px; }
.movement-material strong, .movement-material span { display: block; }
.movement-material span { margin-top: 2px; color: var(--muted); font-size: .72rem; }

/* Compact areas */
.compact-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.compact-grid > div { padding: .9rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.compact-grid strong, .compact-grid span { display: block; }
.compact-grid span { margin-top: .2rem; color: var(--muted); font-size: .84rem; }
.action-bar { position: sticky; bottom: 12px; z-index: 5; padding: 1rem 1.2rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: #344054; border: 1px solid var(--border); border-radius: 15px; background: rgba(255,255,255,.96); box-shadow: 0 -8px 26px rgba(16,24,40,.11); backdrop-filter: blur(10px); }

/* Login */
.login-page { min-height: 100vh; padding: 26px; display: grid; place-items: center; background: radial-gradient(circle at 10% 10%, #eaf2ff, transparent 32%), #eef3f8; }
.login-layout { width: min(1120px, 100%); min-height: 650px; display: grid; grid-template-columns: 1.15fr .85fr; overflow: hidden; border: 1px solid rgba(255,255,255,.7); border-radius: 28px; background: #fff; box-shadow: var(--shadow-lg); }
.login-visual { position: relative; padding: 46px; display: flex; flex-direction: column; justify-content: space-between; color: #fff; background: var(--caal-navy); overflow: hidden; }
.login-visual::before { content: ""; position: absolute; inset: 0; background: url("../img/construction-login.webp") center / cover no-repeat; }
.login-visual::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(7,27,48,.26), rgba(7,27,48,.92)), linear-gradient(90deg, rgba(7,27,48,.78), rgba(7,27,48,.18)); }
.login-visual > * { position: relative; z-index: 2; }
.login-logo { width: 250px; }
.login-visual-copy { max-width: 480px; }
.login-visual-copy h2 { margin-bottom: 12px; font-size: clamp(2.2rem, 4vw, 3.4rem); line-height: 1.02; letter-spacing: -.035em; }
.login-visual-copy h2 span { color: #ffc44b; }
.login-visual-copy p { margin: 0; color: rgba(255,255,255,.78); font-size: 1rem; }
.login-feature-row { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 25px; }
.login-feature { padding: 7px 10px; color: rgba(255,255,255,.9); border: 1px solid rgba(255,255,255,.2); border-radius: 999px; background: rgba(255,255,255,.08); font-size: .73rem; font-weight: 750; }
.login-form-panel { padding: 48px 52px; display: flex; align-items: center; justify-content: center; }
.login-form-wrap { width: 100%; max-width: 380px; }
.login-mark { width: 64px; height: 64px; margin-bottom: 22px; }
.login-form-wrap h1 { margin-bottom: 7px; color: var(--caal-navy); font-size: 2rem; }
.login-form-wrap > p { margin-bottom: 28px; color: var(--muted); }
.login-form-wrap .form-control { min-height: 49px; }
.login-form-wrap .btn { min-height: 49px; }
.login-note { margin-top: 22px; color: #8791a1; text-align: center; font-size: .73rem; }

@media (min-width: 768px) {
  .col-md-2 { width: 16.666%; }
  .col-md-3 { width: 25%; }
  .col-md-4 { width: 33.333%; }
  .col-md-6 { width: 50%; }
  .col-md-10 { width: 83.333%; }
  .col-md-12 { width: 100%; }
}
@media (min-width: 992px) {
  .col-lg-4 { width: 33.333%; }
  .col-lg-5 { width: 41.666%; }
  .col-lg-7 { width: 58.333%; }
}
@media (min-width: 1200px) {
  .col-xl-4 { width: 33.333%; }
  .col-xl-8 { width: 66.666%; }
}

@media (max-width: 1280px) {
  :root { --sidebar-width: 250px; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .quick-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1020px) {
  .sidebar { transform: translateX(-105%); transition: transform .22s ease; }
  .sidebar-close { display: flex; }
  .sidebar-toggle:checked ~ .app-shell .sidebar { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 45; display: block; visibility: hidden; opacity: 0; background: rgba(7,27,48,.48); backdrop-filter: blur(2px); transition: opacity .22s ease, visibility .22s ease; }
  .sidebar-toggle:checked ~ .app-shell .sidebar-backdrop { visibility: visible; opacity: 1; }
  .app-main { margin-left: 0; }
  .menu-button { display: grid; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .hero-content { width: 72%; }
}
@media (max-width: 780px) {
  .topbar { min-height: 68px; padding: 0 16px; }
  .topbar-subtitle, .status-chip, .topbar-user-copy span { display: none; }
  .topbar-user-copy { padding-left: 0; border-left: 0; }
  .page-content { padding: 20px 15px 30px; }
  .app-footer { padding: 15px; flex-direction: column; align-items: flex-start; }
  .dashboard-hero { min-height: 300px; }
  .dashboard-hero::before { background-position: 63% center; }
  .dashboard-hero::after { background: linear-gradient(90deg, rgba(7,27,48,.96), rgba(7,27,48,.73)); }
  .hero-content { width: 100%; padding: 30px 24px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-card { min-height: 116px; padding: 15px; grid-template-columns: 42px 1fr; gap: 10px; }
  .metric-icon { width: 42px; height: 42px; }
  .metric-copy strong { font-size: 1.65rem; }
  .login-page { padding: 0; background: #fff; }
  .login-layout { min-height: 100vh; grid-template-columns: 1fr; border: 0; border-radius: 0; box-shadow: none; }
  .login-visual { min-height: 250px; padding: 26px; }
  .login-visual-copy h2 { font-size: 2.1rem; }
  .login-visual-copy p, .login-feature-row { display: none; }
  .login-form-panel { padding: 34px 24px 44px; }
  th, td { padding: .7rem; }
  .action-bar { align-items: stretch; flex-direction: column; }
  .action-bar .btn { width: 100%; }
  .compact-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .topbar-title { font-size: .88rem; }
  .topbar-user-copy { display: none; }
  .dashboard-hero { min-height: 335px; }
  .hero-title { font-size: 2rem; }
  .hero-copy { font-size: .9rem; }
  .hero-actions .btn { width: 100%; }
  .stat-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .quick-action { min-height: 88px; }
  .page-heading-actions, .page-heading-actions .btn { width: 100%; }
  .page-heading-actions .btn { flex: 1; }
  .cantidad-despacho { min-width: 115px; }
}
.h-100 { height: 100%; }

/* V6: búsquedas predictivas y consulta de órdenes para residentes */
.autocomplete-native-select {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.autocomplete-select { position: relative; width: 100%; }
.autocomplete-input { padding-right: 42px; }
.autocomplete-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 30px;
  height: 30px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  color: #667085;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
}
.autocomplete-toggle:hover { color: var(--caal-blue); background: var(--caal-blue-soft); }
.autocomplete-options {
  position: absolute;
  z-index: 1200;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 290px;
  overflow-y: auto;
  display: none;
  border: 1px solid #c8d5e4;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(15, 35, 58, .17);
}
.autocomplete-options.open { display: block; }
.autocomplete-option {
  width: 100%;
  min-height: 43px;
  padding: .65rem .78rem;
  display: block;
  color: var(--ink);
  border: 0;
  border-bottom: 1px solid #edf1f5;
  background: #fff;
  text-align: left;
  font-size: .86rem;
  cursor: pointer;
}
.autocomplete-option:last-child { border-bottom: 0; }
.autocomplete-option:hover,
.autocomplete-option.active { color: var(--caal-blue); background: #edf5ff; }
.autocomplete-option.selected { font-weight: 800; }
.autocomplete-empty { padding: .8rem; color: var(--muted); font-size: .82rem; text-align: center; }

.readonly-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: .38rem .72rem;
  color: #38506b;
  border: 1px solid #c8d8e8;
  border-radius: 999px;
  background: #eef5fb;
  font-size: .78rem;
  font-weight: 800;
}
.pending-amount { color: #bc6800; font-weight: 850; }
.order-summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.order-summary-card {
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--caal-blue);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.order-summary-card span,
.order-summary-card strong { display: block; }
.order-summary-card span { color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.order-summary-card strong { margin-top: 4px; color: var(--caal-navy); font-size: 1.65rem; }
.order-summary-card.received { border-left-color: var(--success); }
.order-summary-card.pending { border-left-color: #d88900; }
.order-summary-card.pending strong { color: #a85b00; }

.material-finder-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: #f8fbff;
}
.material-finder-field { position: relative; flex: 1 1 440px; }
.material-finder-suggestions {
  position: absolute;
  z-index: 1100;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  display: none;
  border: 1px solid #c8d5e4;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(15, 35, 58, .17);
}
.material-finder-suggestions.open { display: block; }
.material-suggestion {
  width: 100%;
  padding: .68rem .8rem;
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 10px;
  color: var(--ink);
  border: 0;
  border-bottom: 1px solid #edf1f5;
  background: #fff;
  text-align: left;
  cursor: pointer;
}
.material-suggestion:last-child { border-bottom: 0; }
.material-suggestion:hover { background: #edf5ff; }
.material-suggestion strong { color: var(--caal-blue); }
.material-suggestion span { color: #505d6d; }
.material-result-count { flex: 0 0 auto; color: var(--muted); font-size: .78rem; font-weight: 750; }
.material-row-highlight { animation: materialRowFlash 1.8s ease; }
@keyframes materialRowFlash {
  0%, 100% { background: transparent; }
  18%, 65% { background: #fff2c8; }
}

@media (max-width: 767px) {
  .order-summary-grid { grid-template-columns: 1fr; }
  .material-finder-bar { align-items: stretch; flex-direction: column; }
  .material-finder-field { flex-basis: auto; width: 100%; }
  .material-result-count { align-self: flex-start; }
  .autocomplete-options { max-height: 230px; }
}

/* =========================================================
   V7 · RESPONSIVE COMPLETO
   Optimizado para escritorio, tablet y teléfono
   ========================================================= */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

img,
picture,
video,
canvas {
  max-width: 100%;
  height: auto;
}

.app-main,
.page-content,
.card,
.card-body,
.table-responsive,
.row > *,
.topbar-left,
.topbar-right {
  min-width: 0;
}

/* Mejores áreas táctiles */
.btn,
.sidebar-link,
.menu-button,
.sidebar-close,
.profile-logout,
.autocomplete-option,
.material-suggestion {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Evita que textos, códigos o archivos largos rompan el diseño */
td,
.card,
.compact-grid > div,
.page-heading-copy,
.movement-material,
.profile-copy {
  overflow-wrap: anywhere;
  word-break: normal;
}

@media (max-width: 1020px) {
  body.mobile-nav-open {
    overflow: hidden;
    overscroll-behavior: contain;
  }

  .sidebar {
    width: min(88vw, 320px);
    height: 100vh;
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .sidebar-brand {
    padding-top: max(18px, env(safe-area-inset-top, 0));
  }

  .sidebar-nav {
    overscroll-behavior: contain;
  }

  .topbar {
    padding-top: env(safe-area-inset-top, 0);
  }
}

@media (max-width: 780px) {
  :root {
    --radius: 13px;
    --radius-lg: 18px;
  }

  body {
    font-size: .96rem;
  }

  .topbar {
    min-height: 64px;
    padding-right: max(13px, env(safe-area-inset-right, 0));
    padding-left: max(13px, env(safe-area-inset-left, 0));
    gap: 10px;
  }

  .topbar-left {
    flex: 1 1 auto;
    gap: 10px;
  }

  .topbar-title,
  .topbar-subtitle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .menu-button {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }

  .page-content {
    padding-right: max(13px, env(safe-area-inset-right, 0));
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0));
    padding-left: max(13px, env(safe-area-inset-left, 0));
  }

  .card-body {
    padding: 1rem;
  }

  .card-header {
    min-height: 50px;
    padding: .85rem 1rem;
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-heading {
    align-items: stretch;
  }

  .page-heading-copy,
  .page-heading-actions {
    width: 100%;
  }

  .page-heading-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-heading-actions .btn {
    width: 100%;
  }

  /* Evita el zoom automático de Safari/iPhone al enfocar campos */
  .form-control,
  .form-select,
  .autocomplete-input {
    min-height: 47px;
    font-size: 16px;
  }

  .btn {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 40px;
  }

  .dashboard-hero {
    min-height: 285px;
  }

  .hero-content {
    padding: 27px 21px;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .hero-actions .btn {
    width: 100%;
  }

  .metric-card,
  .quick-action {
    min-width: 0;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .material-finder-bar {
    padding: 1rem;
  }

  .autocomplete-options,
  .material-finder-suggestions {
    max-height: min(320px, 43vh);
    overscroll-behavior: contain;
  }

  .action-bar {
    bottom: max(8px, env(safe-area-inset-bottom, 0));
    padding: .9rem;
  }

  .login-page {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .login-layout {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .login-visual {
    min-height: 220px;
  }

  .login-logo {
    width: min(230px, 70vw);
  }
}

/* Tablas convertidas automáticamente en tarjetas móviles por app-responsive.js */
@media (max-width: 680px) {
  .table-responsive {
    overflow: visible;
  }

  .responsive-data-table,
  .responsive-data-table tbody {
    display: block;
    width: 100%;
  }

  .responsive-data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .responsive-data-table tbody tr {
    display: block;
    margin: 0 0 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(15, 35, 58, .055);
  }

  .responsive-data-table tbody tr:last-child {
    margin-bottom: 0;
  }

  .responsive-data-table tbody tr:hover {
    background: #fff;
  }

  .responsive-data-table tbody td {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 45px;
    padding: .68rem .78rem;
    display: grid;
    grid-template-columns: minmax(96px, 36%) minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #edf1f5;
    text-align: left !important;
    white-space: normal;
  }

  .responsive-data-table tbody td:last-child {
    border-bottom: 0;
  }

  .responsive-data-table tbody td::before {
    content: attr(data-label);
    color: #667085;
    font-size: .69rem;
    font-weight: 850;
    letter-spacing: .035em;
    line-height: 1.25;
    text-transform: uppercase;
  }

  .responsive-data-table tbody td[data-label=""]::before {
    display: none;
  }

  .responsive-data-table tbody td.responsive-empty-cell {
    display: block;
    padding: 1.15rem;
    text-align: center !important;
  }

  .responsive-data-table tbody td.responsive-empty-cell::before {
    display: none;
  }

  .responsive-data-table tbody td .btn,
  .responsive-data-table tbody td > a.btn {
    width: 100%;
  }

  .responsive-data-table tbody td .form-control,
  .responsive-data-table tbody td .form-select,
  .responsive-data-table tbody td .autocomplete-select {
    min-width: 0;
    width: 100%;
  }

  .responsive-data-table .cantidad-despacho {
    min-width: 0;
  }

  .responsive-data-table .text-end,
  .responsive-data-table .text-center {
    text-align: left !important;
  }

  .movement-material {
    max-width: none;
  }

  .order-summary-grid {
    gap: 10px;
  }
}

@media (max-width: 520px) {
  .topbar-right {
    display: none;
  }

  .topbar-left > div:last-child {
    min-width: 0;
  }

  .topbar-title {
    max-width: calc(100vw - 90px);
  }

  .page-content {
    padding-top: 15px;
  }

  .page-heading {
    margin-bottom: 15px;
  }

  .page-heading-actions {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    grid-template-columns: 1fr;
  }

  .dashboard-hero {
    min-height: 315px;
  }

  .dashboard-hero::before {
    background-position: 69% center;
  }

  .hero-content {
    padding: 24px 18px;
  }

  .hero-copy {
    margin-bottom: 17px;
  }

  .metric-card {
    min-height: 102px;
  }

  .quick-action {
    min-height: 82px;
    padding: 13px;
  }

  .card-body,
  .card-header {
    padding-right: .85rem;
    padding-left: .85rem;
  }

  .compact-grid > div {
    padding: .8rem;
  }

  .d-flex.flex-wrap.justify-content-between.align-items-center.gap-2.mb-4 {
    align-items: stretch;
    flex-direction: column;
  }

  .d-flex.flex-wrap.justify-content-between.align-items-center.gap-2.mb-4 > .btn,
  .d-flex.flex-wrap.justify-content-between.align-items-center.gap-2.mb-4 > a.btn {
    width: 100%;
  }

  .responsive-data-table tbody td {
    grid-template-columns: minmax(88px, 34%) minmax(0, 1fr);
    padding: .65rem .7rem;
  }

  .material-suggestion {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .autocomplete-option,
  .material-suggestion {
    min-height: 48px;
  }

  .login-visual {
    min-height: 190px;
    padding: 22px;
  }

  .login-visual-copy h2 {
    font-size: 1.8rem;
  }

  .login-form-panel {
    padding: 27px 18px calc(34px + env(safe-area-inset-bottom, 0));
  }

  .login-mark {
    width: 55px;
    height: 55px;
    margin-bottom: 16px;
  }

  .login-form-wrap h1 {
    font-size: 1.75rem;
  }

  .app-footer {
    padding-bottom: calc(15px + env(safe-area-inset-bottom, 0));
  }
}

@media (max-width: 380px) {
  .sidebar {
    width: 94vw;
  }

  .sidebar-brand a {
    width: 190px;
  }

  .hero-title {
    font-size: 1.75rem;
  }

  .responsive-data-table tbody td {
    display: block;
  }

  .responsive-data-table tbody td::before {
    display: block;
    margin-bottom: 5px;
  }
}

/* Respeta las preferencias de accesibilidad del usuario */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* V9: asignación de varios residentes y bodegueros por obra */
.multi-search-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.multi-search {
  display: grid;
  gap: .65rem;
}

.multi-search-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  min-height: 1.9rem;
}

.multi-search-count,
.multi-search-chip,
.multi-search-more,
.assignment-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: .28rem .65rem;
  font-size: .78rem;
  line-height: 1.2;
}

.multi-search-count {
  background: #0b2b4c;
  color: #fff;
  font-weight: 700;
}

.multi-search-chip,
.assignment-tag {
  background: #eaf2fb;
  color: #0b2b4c;
  border: 1px solid #cfe0f2;
}

.multi-search-more {
  background: #f3f4f6;
  color: #475569;
}

.multi-search-options {
  max-height: 16rem;
  overflow-y: auto;
  border: 1px solid #d7e0ea;
  border-radius: .7rem;
  background: #fff;
  padding: .35rem;
}

.multi-search-option {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin: 0;
  padding: .65rem .7rem;
  border-radius: .5rem;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}

.multi-search-option:hover {
  background: #f4f8fc;
}

.multi-search-option.selected {
  background: #eaf2fb;
  color: #0b2b4c;
  font-weight: 650;
}

.multi-search-empty {
  padding: .85rem;
  text-align: center;
  color: #64748b;
}

.assignment-line {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: .45rem;
  margin-bottom: .55rem;
  font-size: .9rem;
}

.assignment-line span {
  color: #526173;
}

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

.assignment-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .55rem;
}

@media (max-width: 767.98px) {
  .assignment-grid {
    grid-template-columns: 1fr;
  }

  .assignment-line {
    grid-template-columns: 1fr;
    gap: .15rem;
  }

  .multi-search-options {
    max-height: 13rem;
  }
}
