:root {
  --navy: #101c3a;
  --navy-light: #16244a;
  --blue: #2f5bea;
  --blue-dark: #1e40c9;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e4e8f1;
  --text: #1b2333;
  --text-muted: #6b7280;
  --green: #16a34a;
  --green-bg: #e8f8ee;
  --red: #dc2626;
  --red-bg: #fdecec;
  --orange: #d97706;
  --orange-bg: #fdf3e3;
  --blue-bg: #eaf0ff;
  --gray-bg: #eef0f4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* Sidebar */
.sidebar {
  width: 230px;
  background: var(--navy);
  color: #cdd5e8;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand img { height: 28px; width: auto; }
.sidebar-brand .name { font-weight: 700; color: #fff; font-size: 15px; }
.sidebar-brand .sub { font-size: 11px; color: #8b95b3; }
.sidebar nav { flex: 1; padding: 10px 0; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: #b6c0dc;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.05); text-decoration: none; color: #fff; }
.sidebar nav a.active {
  background: var(--navy-light);
  color: #fff;
  border-left-color: var(--blue);
  font-weight: 600;
}
.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12.5px;
}
.sidebar-user .u-name { color: #fff; font-weight: 600; }
.sidebar-user .u-role { color: #8b95b3; }
.sidebar-user a { color: #8b95b3; font-size: 12px; }

/* Main content */
.main { flex: 1; min-width: 0; padding: 26px 32px; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; margin: 0; }
.page-header .date { color: var(--text-muted); font-size: 13px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { font-size: 15px; margin: 0 0 16px; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-card .icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; background: var(--blue-bg);
}
.stat-card .value { font-size: 20px; font-weight: 700; }
.stat-card .label { font-size: 12px; color: var(--text-muted); }

/* Forms */
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #374151; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 38px; overflow: hidden; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,91,234,0.12); }
.field { margin-bottom: 14px; }
.field-row { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: #f7f8fb; text-decoration: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-icon { padding: 7px 9px; }

/* Table */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border);
}
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.badge-gray { background: var(--gray-bg); color: #4b5563; }
.badge-blue { background: var(--blue-bg); color: var(--blue-dark); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }

.margen-bajo { color: var(--red); font-weight: 700; }
.margen-aceptable { color: var(--orange); font-weight: 700; }
.margen-excelente { color: var(--green); font-weight: 700; }

/* Partidas table (cotizacion form) */
.partidas-table textarea { min-width: 220px; }
.partidas-table input[type=number] { min-width: 80px; text-align: right; }
.partidas-table td, .partidas-table th { white-space: nowrap; }
.partidas-table td.col-desc, .partidas-table th.col-desc { white-space: normal; }

.resumen-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.resumen-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13.5px; }
.resumen-row.total { font-weight: 700; font-size: 15px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; }
.resumen-row .val-green { color: var(--green); font-weight: 700; }
.resumen-row .val-red { color: var(--red); font-weight: 700; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: var(--green-bg); color: #0f5c2a; }
.alert-error { background: var(--red-bg); color: #8a1c1c; }
.alert-info { background: var(--blue-bg); color: #1e3a8a; }

.disclaimer { font-size: 11px; color: var(--text-muted); font-style: italic; margin-top: 6px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy); }
.login-card { background: #fff; border-radius: 12px; padding: 36px; width: 360px; }
.login-card img { height: 34px; margin-bottom: 18px; }

.signature-pad { border: 1px dashed var(--border); border-radius: 8px; touch-action: none; background: #fff; cursor: crosshair; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .grid-2, .grid-3, .resumen-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
