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

:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --text-light: #999999;
  --border: #e0e0e0;
  --border-strong: #c8c8c8;
  --accent: #111111;
  --success-bg: #f0faf0;
  --success-border: #b8ddb8;
  --error-bg: #fdf0f0;
  --error-border: #ddb8b8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
  --radius: 8px;
  --radius-sm: 4px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Helvetica Neue', Arial, sans-serif;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── HEADER ─────────────────────────────────────────────── */

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.btn-link:hover {
  color: var(--text);
  border-bottom-color: var(--text);
}

/* ── BUTTONS ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
  line-height: 1;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: #aaa;
}

/* ── FORM ELEMENTS ───────────────────────────────────────── */

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="date"],
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

input:focus, select:focus {
  border-color: var(--accent);
}

select[multiple] {
  padding: 4px;
  height: auto;
}

select[multiple] option {
  padding: 5px 8px;
  border-radius: var(--radius-sm);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.checkbox-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-row span {
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

/* ── ALERTS ──────────────────────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 20px;
  border: 1px solid;
}

.alert-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: #2d5a2d;
}

.alert-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: #5a2d2d;
}

/* ── LOGIN PAGE ──────────────────────────────────────────── */

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

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}

.login-logo p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-form .btn {
  width: 100%;
  justify-content: center;
  padding: 10px;
  font-size: 14px;
  margin-top: 4px;
}

/* ── ADMIN PAGE ──────────────────────────────────────────── */

.admin-page {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 16px;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: #fafafa;
}

.upload-zone input[type="file"] {
  display: none;
}

.upload-zone-text {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

.upload-zone-filename {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-top: 6px;
}

.upload-icon {
  font-size: 28px;
  color: var(--border-strong);
}

.log-info {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.log-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.log-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.log-empty {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── PROVIDER PAGE ───────────────────────────────────────── */

.proveidor-layout {
  display: flex;
  height: calc(100vh - 56px);
}

.filters-panel {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.filters-panel h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.filter-group {
  margin-bottom: 16px;
}

.filter-group label {
  margin-bottom: 4px;
}

.date-range {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.date-range input {
  font-size: 12px;
  padding: 6px 8px;
}

.filters-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.filters-footer .btn {
  width: 100%;
  justify-content: center;
}

.main-content {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ── SUMMARY BAR ─────────────────────────────────────────── */

.summary-bar {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: baseline;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.summary-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.summary-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-sep {
  width: 1px;
  height: 28px;
  background: var(--border);
  align-self: center;
}

/* ── TABLE ───────────────────────────────────────────────── */

.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-sm);
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

thead th.center { text-align: center; }

thead th.sortable {
  cursor: pointer;
  user-select: none;
}

thead th.sortable:hover {
  background: #eaeae8;
  color: var(--text);
}

thead th.sort-asc::after  { content: ' ↑'; color: var(--text); }
thead th.sort-desc::after { content: ' ↓'; color: var(--text); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: #fafafa; }

tbody tr.no-extras {
  opacity: 0.45;
}

tbody td {
  padding: 10px 12px;
  color: var(--text);
  white-space: nowrap;
}

tbody td.center { text-align: center; }

.badge-yes {
  display: inline-block;
  font-size: 13px;
  color: #2d5a2d;
  font-weight: 600;
}

.badge-no {
  display: inline-block;
  color: var(--text-light);
  font-size: 13px;
}

.td-nom {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── FILTERS TOGGLE (ocult en escriptori) ────────────────── */

.filters-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border);
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  text-align: left;
}

/* ── TABLET ≤ 1024px: sidebar col·lapsada ────────────────── */

@media (max-width: 1024px) {
  .proveidor-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 100px);
  }

  .filters-toggle {
    display: flex;
  }

  .filters-panel {
    width: 100%;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px 20px 20px;
    display: none;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0 24px;
    max-height: 65vh;
    overflow-y: auto;
  }

  .filters-panel.open {
    display: flex;
  }

  .filters-panel h2 {
    width: 100%;
    margin-bottom: 12px;
  }

  .filter-group {
    flex: 0 0 calc(50% - 12px);
    min-width: 160px;
  }

  .filters-footer {
    width: 100%;
    margin-top: 4px;
    padding-top: 12px;
  }

  .filters-footer .btn {
    width: auto;
  }

  .summary-sep {
    display: none;
  }

  .summary-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    align-items: start;
  }

  .main-content {
    padding: 16px;
  }

  .table-wrapper {
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 720px;
  }
}

/* ── MÒBIL ≤ 640px ───────────────────────────────────────── */

@media (max-width: 640px) {
  .header-subtitle {
    display: none;
  }

  .header {
    padding: 0 16px;
  }

  /* Filtres: una sola columna */
  .filters-panel {
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 14px 16px;
    gap: 0;
    max-height: 72vh;
  }

  .filter-group {
    flex: none;
    width: 100%;
  }

  /* Resum */
  .summary-bar {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 10px 12px;
  }

  .summary-value {
    font-size: 18px;
  }

  .summary-label {
    font-size: 10px;
  }

  /* Taula */
  table {
    font-size: 12px;
    min-width: 680px;
  }

  thead th,
  tbody td {
    padding: 7px 9px;
  }

  /* Contingut principal */
  .main-content {
    padding: 12px;
    gap: 12px;
  }

  /* Pàgina admin */
  .admin-page {
    padding: 20px 14px;
  }

  .upload-zone {
    padding: 20px 14px;
  }

  .log-info {
    flex-direction: column;
    gap: 14px;
  }

  .page-title {
    font-size: 17px;
  }

  .page-subtitle {
    font-size: 12px;
    margin-bottom: 20px;
  }

  .card {
    padding: 18px;
  }
}

/* ── TELÈFONS PETITS ≤ 400px ─────────────────────────────── */

@media (max-width: 400px) {
  .header {
    padding: 0 12px;
    gap: 8px;
  }

  .header-brand {
    font-size: 11px;
    letter-spacing: 0.02em;
  }

  .header-right {
    gap: 10px;
  }

  .btn-link {
    font-size: 12px;
  }

  .summary-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  table {
    min-width: 620px;
  }

  .login-card {
    padding: 28px 16px;
  }

  .login-logo h1 {
    font-size: 13px;
  }
}
