:root {
  --navy: #202b57;
  --navy-2: #151d3d;
  --cyan: #049fd7;
  --red: #ed1625;
  --yellow: #ffd600;
  --pink: #e50070;
  --ink: #202631;
  --muted: #667085;
  --line: #dfe3e8;
  --soft: #f3f5f6;
  --surface: #ffffff;
  --success: #147a4b;
  --warning: #a65b00;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(24, 32, 56, .07);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--soft); }
body { margin: 0; color: var(--ink); background: var(--soft); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.45; }
a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--cyan); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 184px 1fr auto;
  align-items: center;
  gap: 24px;
  min-height: 72px;
  padding: 8px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.97);
}
.brand { display: block; width: 170px; height: 52px; overflow: hidden; }
.brand img { display: block; width: 100%; height: 100%; object-fit: contain; }
.main-nav { display: flex; align-items: center; gap: 4px; }
.main-nav a { padding: 10px 13px; border-radius: 7px; color: #475467; font-weight: 650; }
.main-nav a:hover, .main-nav a.active { background: #edf8fc; color: var(--navy); }
.main-nav a.active { box-shadow: inset 0 -3px 0 var(--cyan); }
.user-menu { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .88rem; }
.user-menu form { margin: 0; }
.link-button { padding: 0; border: 0; background: none; color: var(--navy); font-weight: 700; }
.install-app-button[hidden] { display: none; }
.nav-toggle { display: none; }

.page-shell { width: min(1480px, 100%); margin: 0 auto; padding: 28px 30px 56px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-head h1 { margin-bottom: 0; font-size: 1.75rem; line-height: 1.15; }
.page-subtitle { margin: 7px 0 0; color: var(--muted); }
.eyebrow { margin-bottom: 5px; color: var(--cyan); font-size: .76rem; font-weight: 800; text-transform: uppercase; }
.head-actions { display: flex; gap: 8px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid #cdd3dc;
  border-radius: 7px;
  background: #fff;
  color: var(--navy);
  font-weight: 700;
}
.button:hover { border-color: var(--cyan); color: var(--navy); }
.button.primary { border-color: var(--navy); background: var(--navy); color: #fff; }
.button.primary:hover { background: var(--navy-2); }
.button.google { border-color: #cdd3dc; background: #fff; color: var(--ink); }
.button.google::before { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 8px; border-radius: 50%; background: #fff; color: #4285f4; font-weight: 850; content: "G"; }
.button.small { min-height: 34px; padding: 5px 10px; font-size: .84rem; }
.button.wide { width: 100%; }

.messages { position: fixed; z-index: 40; top: 82px; right: 20px; width: min(390px, calc(100vw - 40px)); }
.message { margin-bottom: 8px; padding: 12px 14px; border-left: 4px solid var(--cyan); border-radius: 6px; background: #fff; box-shadow: var(--shadow); }
.message.success { border-color: var(--success); }
.message.error { border-color: var(--danger); }

.surface { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.section-head h2 { margin: 0; font-size: 1rem; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(210px, 1.3fr); gap: 10px; margin-bottom: 16px; }
.metric { min-height: 86px; padding: 15px; border-top: 4px solid var(--cyan); border-radius: 7px; background: #fff; box-shadow: var(--shadow); }
.metric span { display: block; color: var(--muted); font-size: .82rem; font-weight: 650; }
.metric strong { display: block; margin-top: 7px; color: var(--navy); font-size: 1.65rem; }
.metric.attention { border-color: var(--red); }
.metric.success { border-color: var(--success); }
.metric.money { border-color: var(--yellow); }
.metric.money strong { font-size: 1.35rem; }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.span-2 { grid-column: 1 / -1; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e9ecf0; text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: #fafbfc; color: var(--muted); font-size: .76rem; font-weight: 800; text-transform: uppercase; }
td { font-size: .9rem; }
tr:last-child td { border-bottom: 0; }
td small, .compact-row small { display: block; margin-top: 2px; color: var(--muted); }
.order-number { color: var(--navy); font-weight: 800; }
.empty { margin: 0; padding: 20px; color: var(--muted); text-align: center; }

.status, .payment { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 8px; border-radius: 6px; background: #eef1f5; color: #475467; font-size: .76rem; font-weight: 750; }
.status-recibido, .status-diseno { background: #eef4ff; color: #2949a6; }
.status-preprensa, .status-impresion { background: #e9f8fd; color: #05739a; }
.status-acabado { background: #fff7df; color: #8a5a00; }
.status-listo, .payment-pagado { background: #eaf8f0; color: var(--success); }
.status-entregado { background: #edf0f4; color: #475467; }
.payment-parcial { background: #fff4e8; color: var(--warning); }
.status-cancelado, .payment-pendiente { background: #fff0ef; color: var(--danger); }
.role-admin { background: #eef4ff; color: var(--navy); }
.role-usuario { background: #edf8fc; color: #05739a; }

.compact-list { display: grid; }
.compact-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid #edf0f2; color: var(--ink); }
.compact-row:last-child { border-bottom: 0; }
.compact-row span { min-width: 0; }
.compact-row strong { display: block; }
.align-right { text-align: right; }
.stage-list { display: grid; padding: 8px 16px 14px; }
.stage-list div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #edf0f2; }
.stage-list div:last-child { border-bottom: 0; }
.stage-list span { color: var(--muted); }
.stage-list strong { color: var(--navy); }
.activity-list { display: grid; padding: 6px 16px 12px; }
.activity-row { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid #edf0f2; }
.activity-row:last-child { border-bottom: 0; }
.activity-row p { margin: 2px 0 0; color: var(--muted); font-size: .86rem; }
.activity-row time { color: var(--muted); font-size: .78rem; }
.activity-dot { width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: var(--cyan); }

.filter-bar { display: grid; grid-template-columns: minmax(250px, 1fr) 210px 180px 90px; gap: 10px; margin-bottom: 14px; }
.clients-filter { grid-template-columns: minmax(250px, 1fr) 90px; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid #cfd5dd; border-radius: 7px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); outline: 3px solid rgba(4,159,215,.13); }
input[type="checkbox"] { width: 18px; min-height: 18px; }

.form-layout { display: grid; gap: 16px; }
.form-section { padding-bottom: 16px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 16px; }
.field-grid label, .stack-form > div, .inline-form > div { display: grid; gap: 5px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.field-wide { grid-column: 1 / -1; }
.field-error, .form-error { color: var(--danger); }
.form-error-list { padding: 14px 16px 0; }
.form-error-list p { margin: 0; }
.new-client-panel { display: none; border-top: 1px solid var(--line); background: #fafbfc; }
.new-client-panel.open { display: block; }
.checkbox-field { align-content: center; grid-template-columns: 1fr auto; }
.checkbox-field span { grid-column: 1; }
.checkbox-field input { grid-column: 2; grid-row: 1; justify-self: end; }
.finish-group { display: grid; gap: 8px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.checkbox-pill { display: flex !important; grid-template-columns: none !important; align-items: center; gap: 8px !important; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fafbfc; color: var(--ink) !important; font-size: .86rem !important; }
.checkbox-pill input { flex: 0 0 auto; }
.partial-deliveries { border-top: 1px solid var(--line); background: #fafbfc; }
.nested-head { min-height: 48px; background: #fff; }
.nested-head h3 { margin: 0; font-size: .95rem; }
.delivery-list { display: grid; gap: 8px; padding: 14px 16px 16px; }
.delivery-row { display: grid; grid-template-columns: 150px 130px 150px 140px minmax(180px, 1fr); gap: 8px; align-items: end; padding: 11px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.delivery-row label { display: grid; gap: 4px; color: var(--muted); font-size: .75rem; font-weight: 700; }
.is-hidden { display: none !important; }
.item-form-list { display: grid; gap: 8px; padding: 14px 16px 0; }
.item-form { display: grid; grid-template-columns: minmax(260px, 1fr) 120px 120px 140px 70px; gap: 8px; align-items: end; padding: 11px; border: 1px solid var(--line); border-radius: 7px; background: #fafbfc; }
.single-price-row { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 8px; padding: 14px 16px 0; }
.item-field { display: grid; gap: 4px; color: var(--muted); font-size: .75rem; font-weight: 700; }
.item-DELETE { align-content: center; justify-items: center; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.order-summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); overflow: hidden; }
.order-summary > div { min-height: 82px; padding: 14px; border-right: 1px solid var(--line); }
.order-summary > div:last-child { border-right: 0; }
.order-summary span:not(.status) { display: block; margin-bottom: 8px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.order-summary strong { display: block; font-size: .92rem; }
.order-summary .balance { color: var(--danger); font-size: 1.08rem; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.detail-main, .detail-side { display: grid; gap: 16px; }
.work-specs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.work-specs div { padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #fafbfc; }
.work-specs dt { color: var(--muted); font-size: .75rem; font-weight: 800; text-transform: uppercase; }
.work-specs dd { margin: 4px 0 0; font-weight: 700; overflow-wrap: anywhere; }
.notes-block { padding: 14px 16px; border-top: 1px solid var(--line); }
.notes-block span { color: var(--muted); font-size: .78rem; font-weight: 700; }
.notes-block p { margin: 5px 0 0; }
.action-panel { overflow: visible; }
.stack-form { display: grid; gap: 12px; padding: 14px; }
.stack-form > div { display: grid; gap: 5px; }
.stack-form label, .inline-form label { color: var(--muted); font-size: .8rem; font-weight: 700; }
.timeline { padding: 10px 16px 16px; }
.timeline-row { position: relative; display: grid; grid-template-columns: 18px 1fr; gap: 8px; padding: 8px 0 12px; }
.timeline-row::before { position: absolute; top: 22px; bottom: -7px; left: 6px; width: 2px; background: #d9e4e8; content: ""; }
.timeline-row:last-child::before { display: none; }
.timeline-marker { position: relative; z-index: 1; width: 14px; height: 14px; margin-top: 3px; border: 3px solid #dff3fa; border-radius: 50%; background: var(--cyan); }
.timeline-row p { margin: 3px 0; color: var(--muted); }
.timeline-row small { color: var(--muted); }
.document-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; padding: 14px 16px; }
.document-list a { display: grid; gap: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #fafbfc; }
.document-list span { color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
.inline-form { display: grid; grid-template-columns: 150px 1fr 1fr auto; gap: 8px; align-items: end; padding: 14px 16px; border-top: 1px solid var(--line); }
.delivery-form { grid-template-columns: 140px 120px 150px minmax(180px, 1fr) auto; }
.row-action { display: flex; align-items: center; gap: 6px; }
.row-action select { min-width: 120px; }
.client-panel dl { display: grid; grid-template-columns: 90px 1fr; margin: 0; padding: 14px; gap: 8px; }
.client-panel dt { color: var(--muted); font-size: .78rem; }
.client-panel dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }

.login-page { min-height: 100vh; background: #fff; }
.login-layout { display: grid; grid-template-columns: minmax(360px, 1.2fr) minmax(360px, .8fr); min-height: 100vh; }
.login-brand { display: grid; place-content: center; padding: 8vw; background: #f5f7f7; }
.login-brand img { width: min(560px, 100%); }
.login-brand h1 { margin: 28px 0 6px; color: var(--navy); font-size: 1.8rem; }
.login-brand p { color: var(--muted); }
.login-form-wrap { display: grid; place-items: center; padding: 30px; border-left: 1px solid var(--line); }
.login-form { display: grid; gap: 18px; width: min(380px, 100%); }
.login-form h2 { margin-bottom: 6px; font-size: 1.5rem; }
.login-form label { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.login-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.login-divider::before, .login-divider::after { flex: 1; height: 1px; background: var(--line); content: ""; }
.form-message { margin: 0; padding: 10px 12px; border-left: 4px solid var(--cyan); border-radius: 6px; background: #f8fafc; color: var(--ink); }
.form-message.error { border-color: var(--danger); }
.error-page { max-width: 620px; margin: 8vh auto 0; padding: 28px; }
.error-page h1 { font-size: 1.55rem; }
.error-page p:not(.eyebrow) { color: var(--muted); }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .order-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .order-summary > div:nth-child(3) { border-right: 0; }
  .order-summary > div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .client-panel { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .app-header { grid-template-columns: 145px 1fr auto; gap: 8px; min-height: 62px; padding: 6px 14px; }
  .brand { width: 138px; height: 46px; }
  .nav-toggle { display: inline-flex; justify-self: end; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--navy); font-weight: 700; }
  .main-nav { position: absolute; top: 61px; right: 12px; left: 12px; display: none; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
  .main-nav.open { display: grid; }
  .user-menu span { display: none; }
  .page-shell { padding: 20px 14px 42px; }
  .page-head { align-items: flex-start; }
  .page-head h1 { font-size: 1.45rem; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric.money { grid-column: 1 / -1; }
  .dashboard-grid, .detail-side { grid-template-columns: 1fr; }
  .span-2, .client-panel { grid-column: auto; }
  .filter-bar, .clients-filter { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .item-form, .single-price-row, .delivery-row { grid-template-columns: 1fr; }
  .item-description { grid-column: 1 / -1; }
  .order-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-summary > div { border-bottom: 1px solid var(--line); }
  .order-summary > div:nth-child(2n) { border-right: 0; }
  .order-summary > div:nth-last-child(-n+2) { border-bottom: 0; }
  .inline-form { grid-template-columns: 1fr; }
  .login-layout { grid-template-columns: 1fr; }
  .login-brand { min-height: 38vh; padding: 35px 24px; }
  .login-brand img { width: min(390px, 100%); }
  .login-brand h1 { margin-top: 16px; font-size: 1.35rem; }
  .login-form-wrap { align-items: start; padding: 34px 24px; border: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 430px) {
  .page-head { display: grid; }
  .head-actions { width: 100%; }
  .head-actions .button { flex: 1; }
  .metric { min-height: 78px; padding: 12px; }
  .metric strong { font-size: 1.35rem; }
  .activity-row { grid-template-columns: 12px 1fr; }
  .activity-row time { grid-column: 2; }
}
