:root {
  --bg: #eef4f8;
  --bg-strong: #dce8ef;
  --panel: #ffffff;
  --panel-soft: #f7fafc;
  --ink: #102033;
  --ink-soft: #26384b;
  --muted: #64748b;
  --line: #d8e3ed;
  --line-strong: #c6d5e1;
  --primary: #00b8e6;
  --primary-dark: #007fa3;
  --primary-2: #24d8a7;
  --gold: #f8c948;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --sidebar: #07111f;
  --sidebar-2: #0d2032;
  --shadow-sm: 0 8px 22px rgba(16, 32, 51, .07);
  --shadow: 0 18px 45px rgba(16, 32, 51, .10);
  --shadow-strong: 0 28px 70px rgba(7, 17, 31, .22);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #f8fbfd 0%, var(--bg) 46%, #e6eff5 100%);
}

body.login-page {
  min-height: 100vh;
  background: linear-gradient(145deg, #050b15 0%, #07111f 48%, #0b2431 100%);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { appearance: none; }

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  overflow: auto;
  color: #dbeafe;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  border-right: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 12px 0 38px rgba(7, 17, 31, .18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 82px;
  margin-bottom: 18px;
  padding: 13px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .055);
  border: 1px solid rgba(255, 255, 255, .11);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
}

.brand img {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  object-fit: contain;
  border-radius: 10px;
  background: #081522;
  padding: 7px;
  border: 1px solid rgba(0, 184, 230, .24);
  box-shadow: 0 12px 24px rgba(0, 0, 0, .25);
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1;
  letter-spacing: 0;
  color: #ffffff;
}

.brand small {
  display: block;
  margin-top: 6px;
  color: #9fb3c8;
  line-height: 1.3;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav a {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 45px;
  padding: 11px 13px 11px 15px;
  border-radius: 8px;
  color: #c7d5e5;
  font-weight: 820;
  border: 1px solid transparent;
  transition: background .18s ease, color .18s ease, transform .18s ease, border-color .18s ease;
}

.nav a:hover {
  transform: translateX(2px);
  color: #ffffff;
  background: rgba(255, 255, 255, .07);
  border-color: rgba(255, 255, 255, .08);
}

.nav a.active {
  color: #04111e;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 13px 26px rgba(0, 184, 230, .20);
}

.sidebar-foot {
  margin-top: 22px;
  padding: 14px;
  border-radius: 8px;
  color: #9fb3c8;
  font-size: 13px;
  line-height: 1.45;
  background: rgba(255, 255, 255, .055);
  border: 1px solid rgba(255, 255, 255, .08);
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  padding: 22px 24px;
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .98), rgba(239, 248, 251, .94));
  border: 1px solid rgba(198, 213, 225, .84);
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: 38px;
  line-height: 1.05;
  letter-spacing: 0;
  color: #0c1b2b;
}

h2 {
  margin: 0 0 14px;
  color: #112235;
  letter-spacing: 0;
  line-height: 1.15;
}

h3 {
  margin: 0 0 10px;
  color: #17283a;
  letter-spacing: 0;
}

p { line-height: 1.55; }

.muted {
  color: var(--muted);
  line-height: 1.55;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid > .panel,
.grid > .card {
  min-width: 0;
}

.grid > .panel {
  margin-bottom: 0;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.panel,
.card {
  position: relative;
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.panel {
  padding: 20px;
  margin-bottom: 18px;
}

.panel::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 0;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--gold));
  opacity: .55;
}

.panel > h2,
.panel > h3 {
  padding-top: 4px;
}

.panel > h2:first-child {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e6edf4;
}

.card {
  padding: 16px;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--line-strong);
}

.panel hr,
hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.metric {
  overflow: hidden;
  min-height: 116px;
  padding: 18px;
  border-left: 0;
  background:
    linear-gradient(145deg, #ffffff 0%, #f8fbfd 100%);
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: 0;
}

.metric:nth-child(2)::before { background: linear-gradient(180deg, var(--primary-2), #8fe66b); }
.metric:nth-child(3)::before { background: linear-gradient(180deg, var(--gold), var(--warn)); }
.metric:nth-child(4)::before { background: linear-gradient(180deg, #60a5fa, #7c3aed); }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.btn {
  min-height: 41px;
  border: 1px solid #d5e1ec;
  border-radius: 8px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #ffffff, #edf4f8);
  color: #102033;
  font-weight: 880;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 6px 14px rgba(16, 32, 51, .06);
  transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(16, 32, 51, .10);
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #04111e;
}

.btn.dark {
  border-color: transparent;
  background: linear-gradient(135deg, #102033, #1e3348);
  color: #fff;
}

.btn.danger {
  border-color: #fecaca;
  background: #fee2e2;
  color: #991b1b;
}

.btn.warn {
  border-color: #fde68a;
  background: #fef3c7;
  color: #92400e;
}

.btn.ok {
  border-color: #bbf7d0;
  background: #dcfce7;
  color: #166534;
}

.btn.small {
  min-height: 33px;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-presupuesto { background: #fff7d6; color: #895d00; border-color: #f7d35d; }
.status-enviado { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.status-aceptado,
.status-cobrada { background: #dcfce7; color: #166534; border-color: #86efac; }
.status-rechazado { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.status-pendiente { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.status-material { background: #ffedd5; color: #9a3412; border-color: #fdba74; }
.status-cobro { background: #fef9c3; color: #854d0e; border-color: #fde047; }

.table-wrap {
  overflow: auto;
  border: 1px solid #e6edf4;
  border-radius: 8px;
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
  vertical-align: top;
}

tr:last-child td { border-bottom: 0; }

tbody tr {
  transition: background .16s ease;
}

tbody tr:hover {
  background: #f7fbfd;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fbfd;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
}

label {
  display: block;
  margin-bottom: 6px;
  color: #475569;
  font-size: 13px;
  font-weight: 870;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd8e5;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
  outline: 3px solid transparent;
  outline-offset: 1px;
  transition: border-color .16s ease, box-shadow .16s ease, outline-color .16s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline-color: rgba(0, 184, 230, .14);
  box-shadow: 0 0 0 1px rgba(0, 184, 230, .18);
}

textarea {
  min-height: 104px;
  resize: vertical;
  line-height: 1.5;
}

.form-grid {
  display: grid;
  gap: 13px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }

.field-row {
  display: grid;
  grid-template-columns: 2fr .75fr .85fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 9px;
  padding: 10px;
  border: 1px solid #e6edf4;
  border-radius: 8px;
  background: #fbfdff;
}

.flash {
  margin-bottom: 16px;
  display: grid;
  gap: 9px;
}

.flash div {
  padding: 11px 13px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #075985;
  font-weight: 780;
  border: 1px solid #bae6fd;
}

.flash .error {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}

.tabs {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tabs > div {
  min-width: 0;
  padding: 14px;
  border-radius: 8px;
  background: #f8fbfd;
  border: 1px solid #e5edf5;
}

.tabs > div > h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid #e2ebf3;
}

.state-tabs {
  display: grid;
  gap: 16px;
}

.state-tab-list {
  display: flex;
  gap: 8px;
  padding: 8px;
  overflow-x: auto;
  border: 1px solid #e2ebf3;
  border-radius: 8px;
  background: #f8fbfd;
  scrollbar-width: thin;
}

.state-tab {
  min-height: 46px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid #d8e3ed;
  border-radius: 8px;
  background: #ffffff;
  color: #26384b;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 32, 51, .05);
}

.state-tab strong {
  min-width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: 999px;
  background: #e8f1f7;
  color: #102033;
  font-size: 13px;
}

.state-tab.active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #04111e;
  box-shadow: 0 12px 24px rgba(0, 184, 230, .18);
}

.state-tab.active strong {
  background: rgba(255, 255, 255, .68);
}

.state-tab-panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid #e5edf5;
  border-radius: 8px;
  background: #f8fbfd;
}

.state-tab-panel[hidden] {
  display: none;
}

.state-tab-panel > h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid #e2ebf3;
}

.work-card {
  border-left: 5px solid var(--primary);
  background: linear-gradient(145deg, #ffffff, #f8fbfd);
}

.work-card .title {
  margin-bottom: 8px;
  color: #102033;
  font-weight: 930;
  line-height: 1.35;
}

.work-card .meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.quick-actions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e6edf4;
}

.money {
  color: #0369a1;
  font-weight: 950;
}

.agenda-priority {
  overflow: hidden;
  border-color: rgba(0, 184, 230, .25);
  background: linear-gradient(135deg, rgba(255,255,255,.98), rgba(239,248,251,.94));
  box-shadow: var(--shadow);
}

.agenda-mini {
  border-left: 5px solid var(--primary);
  background: #ffffff;
}

.agenda-mini strong {
  display: block;
  margin-bottom: 8px;
  color: #0e2538;
}

.alert {
  border-left: 6px solid var(--warn);
}

.alert strong {
  display: block;
  margin-bottom: 8px;
}

.alert p {
  margin: 0 0 12px;
}

.alert-danger {
  border-left-color: var(--danger);
  background: #fff7f7;
}

.alert-warning {
  border-left-color: var(--warn);
  background: #fffaf0;
}

.alert-info {
  border-left-color: var(--primary);
  background: #f0f9ff;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}

.weekday {
  padding: 8px 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 920;
  text-transform: uppercase;
  letter-spacing: 0;
}

.day {
  min-height: 122px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 6px 16px rgba(16, 32, 51, .05);
}

.day > strong {
  display: inline-flex;
  min-width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #f1f6fa;
}

.day.out {
  opacity: .48;
  background: #f7fafc;
}

.day.today {
  border: 2px solid var(--primary);
  box-shadow: 0 12px 26px rgba(0, 184, 230, .14);
}

.day.today > strong {
  color: #04111e;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.event {
  display: block;
  margin-top: 7px;
  padding: 6px 8px;
  border-radius: 10px;
  background: #e0f2fe;
  color: #075985;
  font-size: 12px;
  font-weight: 830;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event.done {
  color: #64748b;
  background: #f1f5f9;
  text-decoration: line-through;
}

.signature-box {
  padding: 12px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: #fbfdff;
}

#signatureCanvas {
  width: 100%;
  max-width: 520px;
  height: 180px;
  display: block;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  touch-action: none;
}

.search-select {
  position: relative;
  width: 100%;
}

.native-select-hidden {
  position: absolute;
  inset: auto auto 0 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.search-select-input {
  padding-right: 38px;
  background:
    linear-gradient(180deg, #ffffff, #f9fcfe);
}

.search-select::after {
  content: "⌄";
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-56%);
  color: var(--muted);
  pointer-events: none;
  font-weight: 900;
}

.search-select-menu {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: min(330px, 52vh);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 44px rgba(16, 32, 51, .18);
}

.search-select-option {
  width: 100%;
  min-height: 42px;
  display: block;
  padding: 10px 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.search-select-option:hover,
.search-select-option.active {
  background: #eaf8fb;
}

.search-select-option.selected {
  color: #04111e;
  background: linear-gradient(135deg, rgba(0,184,230,.18), rgba(36,216,167,.18));
  font-weight: 900;
}

.search-select-empty {
  padding: 12px;
  color: var(--muted);
  text-align: center;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-card {
  width: min(460px, 100%);
  padding: 34px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,251,253,.96));
  border: 1px solid rgba(255,255,255,.30);
  border-radius: 14px;
  box-shadow: var(--shadow-strong);
}

.login-logo-wrap {
  width: 116px;
  height: 116px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #06111f, #0a2537);
  border: 1px solid rgba(0, 184, 230, .24);
  box-shadow: 0 20px 50px rgba(0, 184, 230, .24);
}

.login-card img {
  width: 82px;
  height: 82px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 12px 16px rgba(0, 184, 230, .22));
}

.login-card h1 {
  margin-top: 8px;
  text-align: center;
}

.login-card form {
  display: grid;
  gap: 15px;
  margin-top: 24px;
  padding: 20px;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  text-align: left;
  box-shadow: 0 12px 30px rgba(16, 32, 51, .08);
}

.login-card input {
  min-height: 50px;
  font-size: 16px;
}

.login-card .btn {
  min-height: 50px;
  font-size: 16px;
}

@media (max-width: 1180px) {
  .grid-4,
  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .layout {
    display: block;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: 14px;
  }

  .brand {
    min-height: 72px;
    margin-bottom: 12px;
  }

  .brand img {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav a {
    min-height: 42px;
    justify-content: center;
    text-align: center;
  }

  .sidebar-foot {
    display: none;
  }

  .main {
    padding: 14px;
  }

  .topbar {
    display: grid;
    padding: 18px;
    border-radius: 10px;
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .tabs,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2,
  .span-3,
  .span-4 {
    grid-column: auto;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .calendar {
    grid-template-columns: 1fr;
  }

  .weekday {
    display: none;
  }

  .day {
    min-height: auto;
  }

  .btn-row {
    align-items: stretch;
  }

  .btn-row .btn,
  .btn-row button,
  .btn-row select,
  .btn-row input {
    flex: 1 1 auto;
  }
}

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

  .panel,
  .card {
    border-radius: 8px;
  }

  .panel {
    padding: 16px;
  }

  .login-card {
    padding: 24px;
  }

  .topbar .btn-row {
    display: grid;
  }
}
