/* Winkua — Sistema de tickets · estilo Dirección C (Retail cercano) */

:root {
  --bg: #f6f8f8;
  --surface: #ffffff;
  --ink: #0d0d0d;
  --ink-muted: #666e6e;
  --line: #e4e9e9;
  --accent: #0d0d0d;
  --accent-ink: #ffffff;
  --accent-soft: #e2fffb;
  --brand-cyan: #66fcf1;
  --brand-cyan-ink: #05201d;
  --success: #2f9e6e;
  --success-soft: #e3f5ec;
  --warning: #d98a12;
  --warning-soft: #fbeed7;
  --danger: #d1495b;
  --danger-soft: #fbe6ea;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0c0c0c;
  --surface: #161616;
  --ink: #f2f2f2;
  --ink-muted: #9aa3a3;
  --line: #2a2a2a;
  --accent: #66fcf1;
  --accent-ink: #05201d;
  --accent-soft: #103330;
  --brand-cyan: #66fcf1;
  --brand-cyan-ink: #05201d;
  --success: #3fb883;
  --success-soft: #16281f;
  --warning: #e0ab5c;
  --warning-soft: #2e2414;
  --danger: #e0687a;
  --danger-soft: #2e1720;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Karla', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: 'Sora', system-ui, sans-serif;
  font-weight: 700;
  margin: 0 0 8px;
}

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

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 30px;
  box-shadow: 0 20px 40px -24px rgba(36, 31, 51, 0.25);
}

.auth-card .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-card .brand span {
  font-family: 'Sora', sans-serif; font-weight: 800; font-size: 17px;
}
.auth-card .brand.brand-admin { flex-direction: column; align-items: flex-start; gap: 8px; }
.auth-card .brand.brand-admin .brand-logo { height: 40px; }
.brand-logo { height: 34px; width: auto; display: block; }
[data-theme="dark"] .brand-logo { filter: invert(1); }
.brand-admin-tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-muted); background: var(--accent-soft); padding: 3px 8px; border-radius: 6px;
}

.auth-card p.lead {
  color: var(--ink-muted);
  font-size: 13.5px;
  margin: -8px 0 22px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 7px;
}
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 11px;
  padding: 11px 14px;
  font-size: 13.5px;
  color: var(--ink);
  font-family: inherit;
}
.field input:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.alert {
  border-radius: 11px;
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert.ok      { background: var(--success-soft); color: var(--success); }
.alert.error   { background: var(--danger-soft); color: var(--danger); }
.alert.warning { background: var(--warning-soft); color: var(--warning); }

.foot-link {
  margin-top: 18px;
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-muted);
}

/* ===================== App shell (Panel / Nuevo ticket / Mis tickets) ===================== */

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

.sidebar {
  width: 244px;
  flex: 0 0 244px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 26px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 26px; text-decoration: none; color: inherit; }
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand .brand-logo { height: auto; width: 100%; max-width: 180px; }
.sidebar .brand span { font-family: 'Sora', sans-serif; font-weight: 800; font-size: 17px; }

.sidebar .brand.brand-admin {
  flex-direction: column; align-items: flex-start; gap: 10px;
}
.sidebar .brand.brand-admin .brand-admin-tag { margin: 0; }

.nav-list { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  color: var(--ink-muted); font-size: 13.5px;
}
.nav-item svg { flex: 0 0 18px; stroke: var(--ink-muted); }
.nav-item:hover { color: var(--ink); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav-item.active svg { stroke: var(--accent); }

.sidebar .spacer { flex: 1 1 auto; }

.sidebar .foot {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.profile-row { display: flex; align-items: center; gap: 10px; border-radius: 12px; padding: 6px; margin: -6px; transition: background .15s; }
.profile-row:hover { background: var(--bg); text-decoration: none; }
.profile-avatar {
  width: 32px; height: 32px; border-radius: 11px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex: 0 0 32px;
}
.profile-name { font-size: 12.5px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-email { font-size: 11px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-link { font-size: 10.5px; font-weight: 700; color: var(--accent); margin-top: 2px; }
.wa-cta {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 13px; background: var(--bg); border-radius: 12px;
  font-size: 12px; font-weight: 600; color: var(--ink-muted);
}
.terms-link { font-size: 11.5px; color: var(--ink-muted); padding: 0 3px; }

.theme-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 10px 13px; background: var(--bg); border: none; border-radius: 12px;
  font-size: 12px; font-weight: 600; color: var(--ink-muted); cursor: pointer; font-family: inherit;
}
.theme-toggle:hover { color: var(--ink); }
.theme-toggle svg { flex: 0 0 15px; width: 15px; height: 15px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }

.main { flex: 1 1 auto; padding: 34px 40px; min-width: 0; }
.main-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 26px; gap: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--accent); margin-bottom: 6px; }
.page-title { font-family: 'Sora', sans-serif; font-size: 23px; font-weight: 700; }
.btn-cta {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); padding: 12px 20px; border-radius: 14px;
  font-size: 13px; font-weight: 700; box-shadow: 0 8px 18px -8px rgba(13,13,13,.35);
  white-space: nowrap;
}
.btn-cta:hover { text-decoration: none; filter: brightness(1.04); }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 17px 20px; }
.stat-label { font-size: 11.5px; font-weight: 700; margin-bottom: 9px; }
.stat-value { font-family: 'Sora', sans-serif; font-size: 27px; font-weight: 700; }

.content-cols { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.col-main { flex: 1 1 480px; min-width: 0; }
.col-side { width: 290px; flex: 0 0 290px; }

.block-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; }

.data-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.data-card .empty { padding: 24px 18px; text-align: center; color: var(--ink-muted); font-size: 13px; }

table.tickets-table { width: 100%; border-collapse: collapse; }
table.tickets-table th {
  text-align: left; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-muted); background: var(--bg); padding: 10px 18px; border-bottom: 1px solid var(--line);
}
table.tickets-table td { padding: 13px 18px; border-bottom: 1px solid var(--line); font-size: 12.5px; vertical-align: middle; }
table.tickets-table tr:last-child td { border-bottom: none; }
table.tickets-table td a { color: var(--ink); }
.t-num { font-family: 'Space Mono', monospace; font-size: 12.5px; font-weight: 700; color: var(--accent); }

.tnum-copy-wrap { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.tnum-lg { font-family: 'Space Mono', monospace; font-size: 18px; font-weight: 700; color: var(--accent); letter-spacing: .01em; }
.tnum-copy-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-muted); cursor: pointer; padding: 0; flex: 0 0 30px;
  transition: background .15s, color .15s, border-color .15s;
}
.tnum-copy-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tnum-copy-btn svg { width: 16px; height: 16px; }
.tnum-copy-btn.copied { border-color: var(--success); color: var(--success); background: var(--success-soft); }

/* Tiempo dedicado (ticket_horas) */
.horas-total { font-family: 'Space Mono', monospace; font-weight: 700; color: var(--ink); }
.horas-list { display: flex; flex-direction: column; gap: 0; }
.horas-item { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.horas-item:last-child { border-bottom: none; }
.horas-item .row1 { display: flex; justify-content: space-between; align-items: baseline; }
.horas-item .h { font-family: 'Space Mono', monospace; font-weight: 700; color: var(--accent); }
.horas-item .meta { color: var(--ink-muted); font-size: 10.5px; }
.horas-item .nota { color: var(--ink-muted); margin-top: 2px; }
.t-subject { display: block; max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pill { font-size: 10.5px; font-weight: 700; padding: 4px 10px; border-radius: 20px; display: inline-block; }
.pill.abierto { background: var(--danger-soft); color: var(--danger); }
.pill.proceso { background: var(--danger-soft); color: var(--danger); }
.pill.cerrado { background: var(--success-soft); color: var(--success); }
.prio-alta { color: var(--danger); font-weight: 700; }
.prio-normal { color: var(--ink-muted); font-weight: 700; }
.prio-baja { color: var(--ink-muted); font-weight: 700; }

.invoice-list { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.invoice-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 11px; border-bottom: 1px solid var(--line); }
.invoice-row:last-child { border-bottom: none; }
.invoice-num { font-family: 'Space Mono', monospace; font-size: 11px; }
.invoice-date { font-size: 10.5px; color: var(--ink-muted); }
.invoice-amount { font-family: 'Space Mono', monospace; font-size: 12px; font-weight: 700; text-align: right; }
.invoice-status { font-size: 9.5px; font-weight: 700; text-align: right; }
.invoice-status.pendiente { color: var(--warning); }
.invoice-status.pagada { color: var(--success); }

/* Formulario Nuevo ticket */
.ticket-form-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px 30px; max-width: 640px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field select {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 11px;
  padding: 11px 14px; font-size: 13.5px; color: var(--ink); font-family: inherit; appearance: none;
}
.priority-group { display: flex; gap: 8px; }
.priority-opt {
  padding: 8px 17px; border-radius: 20px; border: 1px solid var(--line); font-size: 12.5px; color: var(--ink-muted);
  cursor: pointer; background: var(--surface);
}
.priority-opt input { display: none; }
.priority-opt:has(input:checked) { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.file-upload {
  border: 1.5px dashed var(--line); border-radius: 11px; padding: 14px 16px; background: var(--bg);
  display: flex; flex-direction: column; gap: 9px;
}
.file-upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-upload-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.file-upload-btn {
  display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  font-size: 12.5px; font-weight: 700; font-family: inherit;
  padding: 9px 16px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.file-upload-btn:hover { filter: brightness(0.97); }
.file-upload-input:focus-visible ~ .file-upload-row .file-upload-btn { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-upload-list { font-size: 12px; color: var(--ink-muted); flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.file-upload-hint { font-size: 11.5px; color: var(--ink-muted); }
.check-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; color: var(--ink-muted); }
.form-actions { display: flex; gap: 10px; padding-top: 6px; }
.form-actions .btn { width: auto; padding: 12px 24px; }

/* ===================== Admin ===================== */
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; line-height: 1.4; }
.pill.pendiente { background: var(--warning-soft); color: var(--warning); }
.pill.aprobado  { background: var(--success-soft); color: var(--success); }
.pill.rechazado { background: var(--danger-soft); color: var(--danger); }
.pill.pagada    { background: var(--success-soft); color: var(--success); }
.btn.auto { width: auto; display: inline-flex; }
.filters-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.filters-bar .field { margin: 0; }
.filters-bar select { border: 1px solid var(--line); background: var(--bg); border-radius: 11px; padding: 11px 14px; font-size: 13px; color: var(--ink); font-family: inherit; }
.kv-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; font-size: 12.5px; color: var(--ink-muted); line-height: 2; }
.kv-card b { color: var(--ink); }
.btn-xs {
  font-size: 11.5px; font-weight: 700; padding: 6px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; font-family: inherit;
}
.btn-xs-ok { border-color: var(--success); color: var(--success); }
.btn-xs-ok:hover { background: var(--success-soft); }
.btn-xs-danger { border-color: var(--danger); color: var(--danger); }
.btn-xs-danger:hover { background: var(--danger-soft); }
.close-form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.close-form-row .field { flex: 1 1 140px; margin-bottom: 12px; }

/* Ficha de empresa / facturación (área clientes y admin > clientes) */
.profile-card {
  display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 24px; margin-bottom: 22px;
}
.entity-main { display: flex; align-items: flex-start; gap: 16px; min-width: 220px; }
.entity-avatar {
  width: 52px; height: 52px; border-radius: 14px; flex: 0 0 52px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Sora', sans-serif; font-weight: 800; font-size: 19px;
}
.entity-name { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 17px; margin-bottom: 3px; }
.entity-sub { font-size: 12px; color: var(--ink-muted); }
.entity-meta { display: grid; grid-template-columns: repeat(2, minmax(150px, 1fr)); gap: 8px 30px; }
.entity-meta .k { color: var(--ink-muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.entity-meta .v { color: var(--ink); font-size: 12.5px; font-family: 'Space Mono', monospace; }

/* Filtros extendidos (período, limpiar, contador) */
.filters-bar .filters-clear { font-size: 12px; color: var(--ink-muted); text-decoration: underline; padding-bottom: 12px; }
.filters-bar .filters-count { font-size: 12px; color: var(--ink-muted); padding-bottom: 12px; white-space: nowrap; }
.filters-bar .filters-spacer { flex: 1; }

/* Checkbox de selección de fila */
table.tickets-table th.chk-col, table.tickets-table td.chk-col { width: 36px; padding-right: 4px; padding-left: 18px; }
input[type=checkbox].row-chk { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* Botones de icono (ver / descargar PDF) */
.row-actions { display: flex; gap: 6px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-muted); flex: 0 0 30px;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); text-decoration: none; }
.icon-btn svg { width: 15px; height: 15px; }

/* Barra de descarga masiva (selección de facturas) */
.bulk-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 12px;
  padding: 11px 18px; margin-bottom: 14px; font-size: 12.5px; color: var(--accent); font-weight: 700;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .btn-cta { padding: 9px 16px; font-size: 12.5px; }

@media (max-width: 880px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; flex-direction: row; align-items: center; flex-wrap: wrap; position: static; height: auto; overflow: visible; }
  .nav-list { flex-direction: row; flex-wrap: wrap; }
  .sidebar .foot { display: none; }
  .main { padding: 24px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
