@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/*
  Token values copied bit-for-bit from kopilotti-sales' styles.css /
  styles/vehicle.css (same :root block, same WCAG-computed pairs) — this is
  admin's own copy, not a shared file, so the two repos stay independently
  deployable, but the values must never drift from the source of truth.
  See that file's own header comment for the full contrast-ratio rationale;
  not repeated here to avoid the two copies silently disagreeing over time.
*/
:root {
  --bg: #F5F7FA;
  --white: #FFFFFF;
  --surface: #FFFFFF;
  --surface2: #F5F7FA;
  --border: #E5E7EB;

  --text: #1A1A2E;
  --text2: #4B5565;
  --muted: #6B7280;

  --primary: #1F4DB8;
  --primary-dark: #163A8C;
  --primary-light: #EDF1F9;

  --success: #16A34A;
  --success-text: #117F3A;
  --success-light: #ECF8F1;

  --warning: #F59E0B;
  --warning-text: #9D6507;
  --warning-light: #FEF7EB;

  --error: #DC2626;
  --error-text: #D32424;
  --error-light: #FCEEEE;

  --shadow: 0 1px 3px rgba(17,24,39,0.06), 0 4px 12px rgba(17,24,39,0.04);
  --shadow-lg: 0 8px 32px rgba(17,24,39,0.14);

  --header-bg: #101B3D;
  --header-border: #24304F;
  --header-text: #FFFFFF;
  --header-text-muted: #A8B3CC;
  --header-badge-bg: #1B2748;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 40px;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --text-2xs: 11px;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 30px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: var(--text-sm);
  line-height: 1.5;
}

/* ============ Header (same 3-zone shape as kopilotti-sales' .store-header) ============ */
.store-header {
  min-height: 64px;
  padding: 0 var(--space-4);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}
.store-brand { color: var(--header-text); text-decoration: none; display: flex; align-items: center; gap: 10px; }
.store-brand-mark {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center; color: white;
  font-weight: 700; font-size: var(--text-md); flex-shrink: 0;
}
.store-brand-texts { display: flex; flex-direction: column; line-height: 1.2; }
.store-brand strong { font-size: var(--text-sm); }
.store-brand small { color: var(--header-text-muted); font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: .06em; }

.header-badge {
  display: flex; align-items: center; gap: 8px; background: var(--header-badge-bg);
  border: 1px solid var(--header-border); padding: 5px 12px; border-radius: 100px;
  font-size: var(--text-xs); color: var(--header-text); font-weight: 500;
}
.header-badge-role { color: var(--header-text-muted); font-size: var(--text-2xs); }
.header-logout {
  background: transparent; border: 1px solid var(--header-border); color: var(--header-text-muted);
  font-size: var(--text-xs); font-weight: 600; padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.header-logout:hover { color: var(--header-text); border-color: var(--header-text-muted); }

/* ============ App shell ============ */
.app { max-width: 920px; margin: 0 auto; padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-3); }
@media (min-width: 640px) { .app { padding: var(--space-4); gap: var(--space-4); } }

.page-title { font-size: var(--text-lg); font-weight: 700; }
.page-subtitle { color: var(--muted); font-size: var(--text-xs); margin-top: 2px; }

/* ============ Login ============ */
.login-shell { max-width: 380px; margin: 15vh auto; padding: var(--space-4); }
.login-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3);
}
.login-card h1 { font-size: var(--text-lg); }
.login-card p { color: var(--muted); font-size: var(--text-xs); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: var(--text-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text2); }
.field input {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: var(--text-sm); color: var(--text); background: var(--white);
}
.field input:focus-visible { outline: none; border-color: var(--primary); }
.form-error { color: var(--error-text); font-size: var(--text-xs); min-height: 16px; }

/* ============ Buttons (same tokens as kopilotti-sales' .btn family) ============ */
.btn {
  padding: 10px 18px; border-radius: var(--radius-sm); border: none; font-family: inherit;
  font-size: var(--text-xs); font-weight: 600; cursor: pointer; transition: all .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; width: 100%; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-outline:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: var(--text-2xs); border-radius: 7px; }

/* ============ Location cards ============ */
.location-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; box-shadow: var(--shadow);
}
.location-row {
  padding: var(--space-3); display: flex; align-items: center; gap: var(--space-3); cursor: pointer;
  flex-wrap: wrap;
}
.location-row:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.location-main { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 4px; }
.location-name { font-weight: 700; font-size: var(--text-sm); }
.location-count { color: var(--muted); font-size: var(--text-xs); }
.location-pills { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.location-toggle-wrap { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ============ Pills / badges — pill-shaped, light bg + darkened same-hue
   text, same WCAG-checked pairs as kopilotti-sales' styles.css. Never invent
   a new color pair here. ============ */
.pill {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 100px;
  font-size: var(--text-2xs); font-weight: 700; white-space: nowrap;
}
.pill-success { background: var(--success-light); color: var(--success-text); }
.pill-warning { background: var(--warning-light); color: var(--warning-text); }
.pill-error { background: var(--error-light); color: var(--error-text); }
.pill-muted { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }

/* ============ Toggle switch ============ */
.toggle { position: relative; display: inline-flex; align-items: center; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle-track {
  position: absolute; inset: 0; background: var(--border); border-radius: 100px; transition: background .15s;
}
.toggle-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: white; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s;
}
.toggle input:checked + .toggle-track { background: var(--success); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle input:disabled + .toggle-track { opacity: .45; cursor: not-allowed; }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.toggle-disabled-note { font-size: var(--text-2xs); color: var(--muted); }

/* ============ Expanded vehicle panel ============ */
.location-detail { border-top: 1px solid var(--border); background: var(--surface2); padding: var(--space-3); display: none; }
.location-detail.open { display: block; }

.vehicle-search { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); }
.vehicle-search input {
  flex: 1; min-width: 0; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: var(--text-xs); color: var(--text); background: var(--white);
}
.vehicle-search input:focus-visible { outline: none; border-color: var(--primary); }

.vehicle-table-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.vehicle-table { width: 100%; border-collapse: collapse; font-size: var(--text-xs); }
.vehicle-table th {
  text-align: left; padding: 10px 12px; font-size: var(--text-2xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.vehicle-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.vehicle-table tr:last-child td { border-bottom: none; }
.vehicle-table .col-price { text-align: right; font-variant-numeric: tabular-nums; }
.vehicle-table .col-reg { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-weight: 600; }
.vehicle-table .col-model { color: var(--text2); }
.vehicle-empty, .vehicle-loading { padding: var(--space-4); text-align: center; color: var(--muted); font-size: var(--text-xs); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: var(--space-3); flex-wrap: wrap; }
.pagination-page {
  min-width: 32px; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: white; color: var(--text2); font-size: var(--text-xs); font-weight: 600; cursor: pointer;
}
.pagination-page:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination-page[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: white; }
.pagination-page:disabled { opacity: .4; cursor: not-allowed; }

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: white; padding: 10px var(--space-3); border-radius: 100px;
  font-size: var(--text-xs); font-weight: 500; transition: transform .4s cubic-bezier(.16,1,.3,1);
  z-index: 200; max-width: 90vw; box-shadow: var(--shadow-lg);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--error-text); }

/* ============ View tabs (Toimipisteet / Aktiiviset lukot) ============ */
.view-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.view-tab {
  padding: 10px 14px; border: none; background: none; font: inherit; font-size: var(--text-sm); font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.view-tab:hover { color: var(--text); }
.view-tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

.muted { color: var(--muted); }

/* ============ Negotiation locks ============ */
.lock-list { margin-top: var(--space-3); }

/* ============ Confirmation dialog ============ */
dialog {
  border: none; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 0;
  max-width: 420px; width: calc(100vw - var(--space-4));
}
dialog::backdrop { background: rgba(15, 23, 42, .5); }
dialog form { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
dialog h2 { font-size: var(--text-md); }
dialog p { color: var(--text2); font-size: var(--text-sm); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-2); }
.dialog-actions .btn { width: auto; }

.hidden { display: none !important; }

/* ============ Negotiation policy + Magic Link dialog ============ */
.negotiation-dialog { max-width: 560px; }
.negotiation-dialog-vehicle { color: var(--text2); font-size: var(--text-sm); margin-top: -4px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2) var(--space-3); }
.field-checkbox { flex-direction: row; align-items: center; }
.field-checkbox label { display: flex; align-items: center; gap: 6px; font-size: var(--text-sm); font-weight: 400; text-transform: none; letter-spacing: normal; color: var(--text); }
.negotiation-dialog-divider { border: none; border-top: 1px solid var(--border); margin: var(--space-2) 0; }
.negotiation-link-status { font-size: var(--text-sm); color: var(--text2); }
.negotiation-link-help { font-size: var(--text-xs); color: var(--muted); }
.negotiation-link-result label { font-size: var(--text-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text2); }
.negotiation-link-copy-row { display: flex; gap: var(--space-2); }
.negotiation-link-copy-row input { flex: 1; font-family: ui-monospace, monospace; font-size: var(--text-xs); }

@media (max-width: 480px) {
  .field-grid { grid-template-columns: 1fr; }
}

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
