:root {
  --brand:        #1a56db;
  --brand-dark:   #1241b0;
  --brand-light:  #3b82f6;
  --sidebar-bg:   #0f172a;
  --sidebar-w:    240px;
  --header-h:     52px;
  --text:         #111827;
  --text-muted:   #6b7280;
  --text-light:   #9ca3af;
  --border:       #e5e7eb;
  --border-light: #f3f4f6;
  --bg:           #f9fafb;
  --bg-white:     #ffffff;
  --bg-card:      #ffffff;
  --radius:       3px;
  --radius-lg:    4px;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.06);
  --shadow:       0 1px 4px rgba(0,0,0,.08);
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:    'SF Mono', 'Fira Code', monospace;

  --green:        #16a34a;
  --green-bg:     #f0fdf4;
  --amber:        #d97706;
  --amber-bg:     #fffbeb;
  --red:          #dc2626;
  --red-bg:       #fef2f2;
  --blue:         #1a56db;
  --blue-bg:      #eff6ff;
  --gray:         #6b7280;
  --gray-bg:      #f9fafb;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
img { max-width: 100%; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

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

.sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 200; transition: transform .25s ease; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 0 16px; height: var(--header-h); border-bottom: 1px solid rgba(255,255,255,.06); flex-shrink: 0; min-width: 0; }
.sidebar-logo-img { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.sidebar-logo-placeholder { width: 28px; height: 28px; background: var(--brand); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.sidebar-app-logo { height: 70px; width: auto; object-fit: contain; flex-shrink: 0; filter: brightness(0) invert(1); }
.sidebar-logo-sep { width: 1px; height: 16px; background: rgba(255,255,255,0.15); flex-shrink: 0; }
.sidebar-empresa { color: rgba(255,255,255,0.65); font-size: 12px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-section { padding: 14px 16px 4px; font-size: 10px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase; color: rgba(255,255,255,.25); }
.sidebar-link { display: flex; align-items: center; gap: 9px; padding: 8px 16px; color: rgba(255,255,255,.6); font-size: 13px; transition: background .12s, color .12s; border-left: 2px solid transparent; }
.sidebar-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar-link.active { background: rgba(26,86,219,.2); color: #fff; border-left-color: var(--brand); }
.sidebar-link svg { width: 15px; height: 15px; flex-shrink: 0; opacity: .7; }
.sidebar-link.active svg { opacity: 1; }
.sidebar-footer { padding: 10px 16px; border-top: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
.sidebar-user { display: flex; align-items: center; gap: 9px; }
.sidebar-avatar { width: 30px; height: 30px; background: var(--brand); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 600; flex-shrink: 0; overflow: hidden; }
.sidebar-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { color: #fff; font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { color: rgba(255,255,255,.35); font-size: 11px; }
.sidebar-logout { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; color: rgba(255,255,255,.4); border-radius: 2px; flex-shrink: 0; }
.sidebar-logout:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-logout svg { width: 14px; height: 14px; }

.main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.header { height: var(--header-h); background: var(--bg-white); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 10px; position: sticky; top: 0; z-index: 100; }
.header-toggle { display: none; background: none; border: none; padding: 5px; color: var(--text-muted); }
.header-toggle svg { width: 18px; height: 18px; display: block; }
.header-breadcrumb { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-muted); }
.header-breadcrumb a { color: var(--text-muted); }
.header-breadcrumb a:hover { color: var(--text); }
.header-breadcrumb .sep { color: var(--border); }
.header-breadcrumb .current { color: var(--text); font-weight: 500; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.lang-dropdown { position: relative; }
.lang-btn { display: flex; align-items: center; gap: 5px; padding: 4px 9px; border: 1px solid var(--border); background: var(--bg-white); font-size: 12px; color: var(--text-muted); cursor: pointer; border-radius: var(--radius); }
.lang-btn:hover { border-color: #d1d5db; color: var(--text); }
.lang-btn svg { width: 12px; height: 12px; }
.lang-menu { display: none; position: absolute; right: 0; top: calc(100% + 4px); background: var(--bg-white); border: 1px solid var(--border); min-width: 100px; z-index: 300; box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.lang-menu.open { display: block; }
.lang-menu a { display: block; padding: 7px 12px; font-size: 12.5px; color: var(--text); }
.lang-menu a:hover { background: var(--bg); }
.lang-menu a.active { font-weight: 500; color: var(--brand); }

.page-content { padding: 20px; flex: 1; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-title { font-size: 18px; font-weight: 600; color: var(--text); line-height: 1.2; }
.page-subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.card { background: var(--bg-card); border: 1px solid var(--border); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border-light); gap: 10px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text); }
.card-body { padding: 16px; }
.card-footer { padding: 10px 16px; border-top: 1px solid var(--border-light); background: var(--bg); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); margin-bottom: 20px; }
.stat-card { background: var(--bg-white); padding: 16px 18px; display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 18px; height: 18px; }
.stat-icon.brand  { color: var(--brand); }
.stat-icon.green  { color: var(--green); }
.stat-icon.blue   { color: var(--blue); }
.stat-icon.amber  { color: var(--amber); }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.stat-detail { font-size: 11px; color: var(--text-light); margin-top: 2px; }

.btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; font-size: 13px; font-weight: 500; border: 1px solid transparent; transition: background .12s, border-color .12s, color .12s; white-space: nowrap; line-height: 1.4; cursor: pointer; border-radius: var(--radius); }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-primary   { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-secondary { background: var(--bg-white); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }
.btn-danger    { background: var(--bg-white); color: var(--red); border-color: #fca5a5; }
.btn-danger:hover { background: var(--red-bg); }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn-sm svg { width: 12px; height: 12px; }
.btn-lg { padding: 9px 18px; font-size: 14px; }

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.form-label .req { color: var(--red); margin-left: 2px; }
.form-control { width: 100%; padding: 7px 10px; border: 1px solid var(--border); font-size: 13px; color: var(--text); background: var(--bg-white); transition: border-color .12s, box-shadow .12s; line-height: 1.4; border-radius: var(--radius); }
.form-control:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(26,86,219,.1); }
.form-control::placeholder { color: var(--text-light); }
.form-control[readonly] { background: var(--bg); color: var(--text-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 76px; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.form-error { font-size: 11.5px; color: var(--red); margin-top: 3px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 9px 14px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--bg); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border-light); vertical-align: middle; color: var(--text); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafafa; }
.data-table .td-actions { white-space: nowrap; text-align: right; }
.data-table .td-actions .btn { margin-left: 3px; }

.badge { display: inline-flex; align-items: center; padding: 2px 7px; font-size: 11px; font-weight: 500; white-space: nowrap; border-radius: 2px; }
.badge-green  { background: var(--green-bg);  color: #15803d; }
.badge-red    { background: var(--red-bg);    color: #b91c1c; }
.badge-amber  { background: var(--amber-bg);  color: #b45309; }
.badge-blue   { background: var(--blue-bg);   color: #1e40af; }
.badge-gray   { background: var(--gray-bg);   color: var(--gray); border: 1px solid var(--border); }
.badge-brand  { background: var(--blue-bg);   color: var(--brand); }

.filters-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters-bar .form-control { width: auto; }
.search-box { position: relative; flex: 1; min-width: 160px; max-width: 260px; }
.search-box svg { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-light); pointer-events: none; }
.search-box input { padding-left: 30px; }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--border-light); font-size: 12px; color: var(--text-muted); flex-wrap: wrap; gap: 8px; }
.pag-pages { display: flex; gap: 2px; }
.pag-pages a, .pag-pages span { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; font-size: 12px; border: 1px solid transparent; color: var(--text-muted); padding: 0 4px; }
.pag-pages a:hover { background: var(--bg); border-color: var(--border); color: var(--text); }
.pag-pages .current { background: var(--brand); color: #fff; border-color: var(--brand); }

.avatar { object-fit: cover; flex-shrink: 0; }
.avatar-sm { width: 26px; height: 26px; font-size: 10px; }
.avatar-md { width: 34px; height: 34px; font-size: 12px; }
.avatar-lg { width: 52px; height: 52px; font-size: 18px; }
.avatar-xl { width: 76px; height: 76px; font-size: 26px; }
.avatar-placeholder { background: var(--brand); color: #fff; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.user-cell { display: flex; align-items: center; gap: 8px; }
.user-cell-info .user-name { font-weight: 500; color: var(--text); font-size: 13px; }
.user-cell-info .user-sub  { font-size: 11.5px; color: var(--text-muted); }

.alert { display: flex; align-items: flex-start; gap: 9px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; border: 1px solid transparent; }
.alert svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--green-bg); color: #15803d; border-color: #bbf7d0; }
.alert-error   { background: var(--red-bg);   color: #b91c1c; border-color: #fecaca; }
.alert-warning { background: var(--amber-bg); color: #b45309; border-color: #fde68a; }
.alert-info    { background: var(--blue-bg);  color: #1e40af; border-color: #bfdbfe; }

.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 500; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg-white); border: 1px solid var(--border); width: 100%; max-width: 500px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 14px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); padding: 3px; line-height: 0; }
.modal-close:hover { color: var(--text); }
.modal-close svg { width: 16px; height: 16px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.photo-thumb { width: 40px; height: 40px; object-fit: cover; border: 1px solid var(--border); cursor: pointer; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state svg { width: 36px; height: 36px; margin: 0 auto 10px; color: var(--border); display: block; }
.empty-state p { font-size: 13px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 8px 14px; font-size: 13px; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 199; }

.fichaje-page { min-height: 100vh; background: var(--bg); display: flex; flex-direction: column; }
.fichaje-header { background: var(--sidebar-bg); padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; }
.fichaje-header-logo { color: #fff; font-size: 14px; font-weight: 600; }
.fichaje-header-user { color: rgba(255,255,255,.6); font-size: 12.5px; display: flex; align-items: center; gap: 10px; }
.fichaje-header-user a { color: rgba(255,255,255,.5); font-size: 12px; }
.fichaje-header-user a:hover { color: #fff; }
.fichaje-body { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 24px 16px; max-width: 480px; margin: 0 auto; width: 100%; }
.fichaje-card { background: var(--bg-white); border: 1px solid var(--border); width: 100%; margin-bottom: 16px; }
.fichaje-perfil { display: flex; flex-direction: column; align-items: center; padding: 24px; text-align: center; }
.fichaje-avatar { width: 72px; height: 72px; background: var(--brand); color: #fff; font-size: 26px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.fichaje-nombre { font-size: 17px; font-weight: 600; color: var(--text); }
.fichaje-rol    { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.fichaje-estado { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 4px 12px; font-size: 12.5px; font-weight: 500; border: 1px solid var(--border); }
.fichaje-estado.dentro  { color: var(--green); border-color: #bbf7d0; background: var(--green-bg); }
.fichaje-estado.fuera   { color: var(--text-muted); background: var(--bg); }
.fichaje-btn-wrap { padding: 0 24px 24px; }
.fichaje-btn { width: 100%; padding: 13px; font-size: 15px; font-weight: 600; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; letter-spacing: .2px; }
.fichaje-btn.entrada { background: var(--brand); color: #fff; }
.fichaje-btn.entrada:hover { background: var(--brand-dark); }
.fichaje-btn.salida  { background: #fff; color: var(--red); border: 1px solid #fca5a5; }
.fichaje-btn.salida:hover  { background: var(--red-bg); }
.fichaje-camara { width: 100%; background: var(--bg-white); border: 1px solid var(--border); overflow: hidden; }
.fichaje-camara video { width: 100%; display: block; max-height: 280px; object-fit: cover; background: #000; }
.fichaje-countdown { font-size: 48px; font-weight: 700; color: var(--brand); text-align: center; padding: 20px; }
.fichaje-obras { padding: 0 24px 16px; }
.fichaje-historial { width: 100%; }
.fichaje-historial-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border-light); font-size: 12.5px; }
.fichaje-historial-item:last-child { border-bottom: none; }
.fichaje-dot { width: 8px; height: 8px; flex-shrink: 0; }
.fichaje-dot.entrada { background: var(--green); }
.fichaje-dot.salida  { background: var(--red); }

.login-page { min-height: 100vh; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: var(--bg-white); border: 1px solid var(--border); width: 100%; max-width: 360px; padding: 32px 28px; }
.login-logo { margin-bottom: 0; }
.login-logo-placeholder { width: 32px; height: 32px; background: var(--brand); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 15px; }
.login-logo-img { height: 77px; width: auto; object-fit: contain; display: block; }
.login-title { font-size: 17px; font-weight: 600; margin-bottom: 2px; }
.login-sub   { font-size: 12.5px; color: var(--text-muted); margin-bottom: 22px; }
.login-box .btn-primary { width: 100%; justify-content: center; padding: 9px; font-size: 13.5px; }
.company-list { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.company-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); cursor: pointer; background: none; width: 100%; text-align: left; transition: border-color .12s; }
.company-item:hover { border-color: var(--brand); }
.company-item-logo { width: 32px; height: 32px; background: var(--brand); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0; overflow: hidden; }
.company-item-logo img { width: 100%; height: 100%; object-fit: cover; }
.company-item-name { font-weight: 500; font-size: 13.5px; color: var(--text); }
.company-item-role { font-size: 11.5px; color: var(--text-muted); }
.company-item-arrow { margin-left: auto; color: var(--text-light); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.25); }
  .sidebar-overlay.open { display: block; }
  .main-wrap { margin-left: 0; }
  .header-toggle { display: flex; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-content { padding: 14px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .login-box { padding: 22px 18px; }
}

.header-chat-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--bg-white);
  text-decoration: none;
  transition: border-color .15s, color .15s;
}
.header-chat-btn:hover,
.header-chat-btn.active {
  border-color: var(--blue);
  color: var(--blue);
}
.chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
}

.photo-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: opacity .15s;
}
.photo-thumb:hover { opacity: .8; }
