/* Tempus: sistema de disseny. Els colors de marca arriben per variables CSS. */
:root {
  --c-primary: #111827;
  --c-accent: #2563eb;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1a202c;
  --text-soft: #64748b;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --warn: #b45309;
  --warn-bg: #fffaeb;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --muted-bg: #f1f3f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; flex-shrink: 0; }
.icon-lg { width: 28px; height: 28px; flex-shrink: 0; }

/* ---- Estructura amb barra lateral ---- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand img { max-height: 34px; max-width: 150px; object-fit: contain; }
.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--c-primary);
}
.sidebar-brand .brand-sub { font-size: 0.78rem; color: var(--text-soft); display: block; }

.sidebar nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--muted-bg); color: var(--text); text-decoration: none; }
.nav-item.active { background: color-mix(in srgb, var(--c-primary) 8%, white); color: var(--c-primary); }
.nav-item .icon { width: 19px; height: 19px; }

.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--text-soft); }
.sidebar-foot .user-line { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; word-break: break-all; }

.main { flex: 1; margin-left: 232px; padding: 28px 32px 48px; max-width: 1200px; }

.topbar { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
  .main { margin-left: 0; padding: 16px 14px 40px; }
  .topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .topbar .brand-name { font-weight: 700; color: var(--c-primary); }
  .backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 35; }
}

/* ---- Capçaleres de pàgina ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.45rem; letter-spacing: -0.02em; }
.page-head .actions { display: flex; gap: 10px; }

/* ---- Targetes ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 { font-size: 1.02rem; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card h2 .icon { color: var(--text-soft); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .stat-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; color: var(--c-primary); }
.stat .stat-label { font-size: 0.83rem; color: var(--text-soft); }

/* ---- Botons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease;
}
.btn:hover { background: var(--muted-bg); text-decoration: none; }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--c-primary) 85%, black); }
.btn-accent { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
.btn-accent:hover { background: color-mix(in srgb, var(--c-accent) 85%, black); }
.btn-danger { background: var(--surface); border-color: #f3c6c6; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---- Insígnies d'estat ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge .icon { width: 13px; height: 13px; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-muted { background: var(--muted-bg); color: var(--text-soft); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-accent { background: color-mix(in srgb, var(--c-accent) 12%, white); color: var(--c-accent); }

/* ---- Taules ---- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafbfc; }

/* ---- Formularis ---- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.86rem; font-weight: 600; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--c-accent) 35%, white);
  border-color: var(--c-accent);
}
.field input[type="color"] { height: 42px; padding: 4px; width: 90px; }
.field .help { font-size: 0.78rem; color: var(--text-soft); margin-top: 4px; }
.field .errors { font-size: 0.8rem; color: var(--danger); margin-top: 4px; }
.form-errors {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f3c6c6;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.86rem;
  margin-bottom: 16px;
}
.form-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-inline .field { margin-bottom: 0; flex: 1; min-width: 140px; }

/* ---- Missatges flash ---- */
.messages { margin-bottom: 18px; }
.message {
  padding: 11px 15px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 8px;
  border: 1px solid;
  word-break: break-word;
}
.message.success { background: var(--ok-bg); color: var(--ok); border-color: #c6ecd4; }
.message.error { background: var(--danger-bg); color: var(--danger); border-color: #f3c6c6; }
.message.info { background: color-mix(in srgb, var(--c-accent) 8%, white); color: var(--c-accent); border-color: color-mix(in srgb, var(--c-accent) 25%, white); }

/* ---- Pantalla d'accés ---- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 34px 32px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand img { max-height: 48px; max-width: 200px; object-fit: contain; margin-bottom: 8px; }
.auth-brand .brand-name { font-size: 1.35rem; font-weight: 700; color: var(--c-primary); letter-spacing: -0.02em; }
.auth-brand .welcome { color: var(--text-soft); font-size: 0.88rem; margin-top: 6px; }
.auth-foot { text-align: center; margin-top: 20px; font-size: 0.78rem; color: var(--text-soft); }

/* ---- Pantalla de fitxar ---- */
.punch-wrap { max-width: 560px; margin: 0 auto; }
.punch-card { text-align: center; padding: 30px 24px; }
.punch-clock { font-size: 2.9rem; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; color: var(--c-primary); }
.punch-date { color: var(--text-soft); font-size: 0.92rem; margin-bottom: 14px; text-transform: capitalize; }
.punch-stats { display: flex; justify-content: center; gap: 28px; margin: 18px 0; }
.punch-stats .stat .stat-value { font-size: 1.25rem; }
.punch-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.punch-actions .btn { padding: 13px 26px; font-size: 1rem; border-radius: 10px; }
.geo-note { font-size: 0.76rem; color: var(--text-soft); margin-top: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; }

.timeline { list-style: none; }
.timeline li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.timeline li:last-child { border-bottom: none; }
.timeline .tl-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 52px; }
.timeline .tl-icon { color: var(--text-soft); }

/* ---- Diversos ---- */
.empty {
  text-align: center;
  color: var(--text-soft);
  padding: 34px 20px;
  font-size: 0.9rem;
}
.empty .icon { width: 34px; height: 34px; margin: 0 auto 10px; display: block; opacity: 0.5; }

.muted { color: var(--text-soft); font-size: 0.85rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.8rem; }
.mt { margin-top: 16px; }
.pagination { display: flex; gap: 8px; align-items: center; margin-top: 16px; font-size: 0.88rem; }

.color-dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; border: 1px solid var(--border); vertical-align: middle; }

/* ---- Calendari d'equip ---- */
.cal-wrap { overflow-x: auto; }
table.cal { border-collapse: collapse; font-size: 0.72rem; width: 100%; }
.cal th, .cal td { border: 1px solid var(--border); padding: 3px 2px; text-align: center; min-width: 24px; }
.cal th { font-weight: 600; color: var(--text-soft); }
.cal .cal-name {
  text-align: left; white-space: nowrap; padding: 5px 10px; font-size: 0.85rem;
  position: sticky; left: 0; background: var(--surface); z-index: 2; min-width: 140px;
}
.cal .we { background: #f3f4f6; }
.cal .hol { background: var(--warn-bg); }
.cal .m-V { background: var(--ok-bg); color: var(--ok); font-weight: 700; }
.cal .m-P { background: color-mix(in srgb, var(--c-accent) 12%, white); color: var(--c-accent); font-weight: 700; }
.cal .m-B { background: #e5e7eb; color: #374151; font-weight: 700; }
.cal-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 0.8rem; color: var(--text-soft); }
.cal-legend .chip { display: inline-block; width: 18px; height: 14px; border-radius: 3px; vertical-align: middle; margin-right: 4px; border: 1px solid var(--border); }
