/* ─────────────────────────────────────────────────────────────────────────
   Design system
   ───────────────────────────────────────────────────────────────────────── */
:root {
  /* Color tokens */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbff;
  --border: #e3e6ee;
  --border-strong: #cdd2de;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  /* Brand */
  --brand-50:  #eff5ff;
  --brand-100: #dbe7fe;
  --brand-500: #3b6df0;
  --brand-600: #2456db;
  --brand-700: #1c44b4;
  --brand-900: #0f1d4a;

  /* Status */
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;

  /* Spacing */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;

  /* Radii / shadows */
  --r1: 6px; --r2: 10px; --r3: 14px; --r4: 20px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-2: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-3: 0 10px 32px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
[hidden] { display: none !important; }

/* Language toggle (pinned top-right) */
.lang-toggle {
  position: fixed; top: 14px; right: 14px; z-index: 200;
  display: inline-flex; gap: 1px; padding: 2px;
  background: rgba(255,255,255,0.9); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: var(--shadow-1); backdrop-filter: blur(6px);
}
.lang-toggle button {
  background: transparent; border: none; cursor: pointer;
  padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.05em; font-family: inherit;
}
.lang-toggle button:hover { color: var(--text); }
.lang-toggle button.active { background: var(--brand-600); color: #fff; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

.muted   { color: var(--text-muted); }
.subtle  { color: var(--text-subtle); }
.small   { font-size: 12px; }
.tight   { letter-spacing: -0.01em; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r1);
  padding: 8px 14px; font-size: 14px; font-weight: 500; line-height: 1.2;
  cursor: pointer; transition: all 0.15s ease;
  font-family: inherit;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary {
  background: var(--brand-600); color: #fff; border-color: var(--brand-600);
  box-shadow: var(--shadow-1);
}
.btn.primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--brand-50); color: var(--brand-700); }
.btn.tiny { padding: 4px 10px; font-size: 12px; }
.btn.lg { padding: 12px 24px; font-size: 15px; }
.btn.icon { padding: 6px; min-width: 32px; }

/* ─── Forms ─── */
.input, .select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--r1);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}
label.field { display: block; margin-bottom: var(--s4); }
label.field .label-text { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em; }
.help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Conditionally-shown fields (data-show-if) */
[data-show-if] { display: none; }
[data-show-if].show { display: block; }

/* ─── Tags / badges ─── */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--brand-50); color: var(--brand-700);
}
.tag.success { background: var(--success-bg); color: var(--success); }
.tag.warn    { background: var(--warn-bg);    color: var(--warn); }
.tag.danger  { background: var(--danger-bg);  color: var(--danger); }
.tag.subtle  { background: #f1f5f9;           color: var(--text-muted); }

/* ─── Avatars ─── */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-700);
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }

/* ─── Login ─── */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(circle at 20% 0%, #dbe7fe 0%, transparent 50%),
    radial-gradient(circle at 80% 100%, #e0e7ff 0%, transparent 50%),
    var(--bg);
  padding: var(--s4);
}
.login-card {
  width: 380px; max-width: 100%; background: var(--surface);
  padding: var(--s6); border-radius: var(--r3);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--border);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
.login-card .lead { color: var(--text-muted); font-size: 14px; margin: 0 0 var(--s5); }
.login-card label { display: block; margin-top: var(--s4); font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.login-card input { margin-top: 5px; }
.login-card .btn { width: 100%; margin-top: var(--s5); padding: 11px; }
.login-card .error { color: var(--danger); margin-top: var(--s3); font-size: 13px; min-height: 1em; }
.login-card .info  { color: var(--success); margin-top: var(--s3); font-size: 13px; min-height: 1em; }
.login-links { margin-top: var(--s4); font-size: 13px; text-align: center; color: var(--text-muted); }
.login-links a { color: var(--brand-600); }

/* ─────────────────────────────────────────────────────────────────────────
   App shell: fixed sidebar + main content
   ───────────────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .logo {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s5) var(--s5) var(--s4);
  font-size: 17px; font-weight: 700; letter-spacing: -0.02em;
}
.sidebar .logo-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 16px;
}
.sidebar nav { flex: 1; padding: var(--s2) var(--s3); display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: var(--s3);
  padding: 9px 12px; border-radius: var(--r1);
  color: var(--text-muted); font-weight: 500; font-size: 14px;
  text-decoration: none;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--brand-50); color: var(--brand-700); }
.sidebar nav a .nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }

.sidebar .user-row {
  margin: 0 var(--s3) var(--s3); padding: var(--s3);
  border-radius: var(--r2); border: 1px solid var(--border);
  display: flex; gap: var(--s3); align-items: center;
}
.sidebar .user-row .who { flex: 1; min-width: 0; padding: 4px 6px; border-radius: 6px; transition: background 0.15s; }
.sidebar .user-row .who:hover { background: var(--surface-2); }
.sidebar .user-row .who .username { font-weight: 600; font-size: 13px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user-row .who .role { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Main */
.main { padding: 0; min-width: 0; }
.page-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg); border-bottom: 1px solid var(--border);
  padding: var(--s5) var(--s6) var(--s4);
}
.page-header .crumbs { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.page-header h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.page-header .actions { margin-top: var(--s4); display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.page-header .actions .search { flex: 1; min-width: 240px; max-width: 480px; }
.page-body { padding: var(--s5) var(--s6) var(--s7); }

/* ─── Card ─── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r2); padding: var(--s5);
  box-shadow: var(--shadow-1);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--brand-100); box-shadow: var(--shadow-2); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--s4); }

/* Contract card */
.contract-card .row { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); }
.contract-card h3 { margin: 0 0 2px; font-size: 15px; line-height: 1.3; letter-spacing: -0.01em; }
.contract-card .type { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.contract-card .meta { margin-top: var(--s3); display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text); }
.contract-card .meta-row { display: flex; gap: 6px; align-items: center; }
.contract-card .meta-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; min-width: 64px; }
.contract-card .footer { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--border); display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }

/* Party / Property card */
.entity-card { display: flex; gap: var(--s3); align-items: flex-start; }
.entity-card .body { flex: 1; min-width: 0; }
.entity-card h4 { margin: 0 0 2px; font-size: 14px; }
.entity-card .sub { color: var(--text-muted); font-size: 12px; line-height: 1.4; }
.entity-card .actions { display: flex; gap: 4px; }

/* Empty states */
.empty-state {
  text-align: center; padding: var(--s7) var(--s5);
  color: var(--text-muted);
}
.empty-state h3 { color: var(--text); font-size: 16px; margin: 0 0 6px; }
.empty-state p { margin: 0 0 var(--s4); }

/* ─── Toolbars / search ─── */
.search-wrap {
  position: relative; flex: 1; min-width: 200px;
}
.search-wrap input {
  width: 100%; padding: 8px 12px 8px 36px;
  border: 1px solid var(--border); border-radius: var(--r1);
  background: var(--surface); font-size: 14px;
}
.search-wrap input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); }
.search-wrap .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }

/* ─────────────────────────────────────────────────────────────────────────
   Wizard (stepped contract creation)
   ───────────────────────────────────────────────────────────────────────── */
.wizard {
  max-width: 880px; margin: 0 auto;
}
.wizard .stepper {
  display: flex; align-items: center; gap: var(--s2);
  margin-bottom: var(--s5);
}
.wizard .step {
  display: flex; align-items: center; gap: var(--s2);
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; font-weight: 500; color: var(--text-muted);
}
.wizard .step.active { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand-700); }
.wizard .step.done { background: #fff; border-color: var(--success); color: var(--success); }
.wizard .step .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--border); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.wizard .step.active .dot { background: var(--brand-600); }
.wizard .step.done .dot { background: var(--success); }
.wizard .step-arrow { color: var(--text-subtle); }
.wizard .step-content { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r2); padding: var(--s6); box-shadow: var(--shadow-1); }
.wizard .step-content h2 { margin: 0 0 var(--s2); font-size: 18px; letter-spacing: -0.01em; }
.wizard .step-content .lead { margin: 0 0 var(--s5); color: var(--text-muted); font-size: 14px; }
.wizard .step-actions { margin-top: var(--s5); display: flex; gap: var(--s2); justify-content: space-between; align-items: center; }

/* Type cards in step 1 */
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s4); }
.type-card {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--r2);
  padding: var(--s5); cursor: pointer; transition: all 0.15s;
  text-align: left;
}
.type-card:hover { border-color: var(--brand-500); transform: translateY(-2px); box-shadow: var(--shadow-2); }
.type-card.selected { border-color: var(--brand-600); background: var(--brand-50); }
.type-card .type-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: grid; place-items: center; color: #fff;
  margin-bottom: var(--s3);
}
.type-card h3 { margin: 0 0 4px; font-size: 15px; letter-spacing: -0.01em; }
.type-card .desc { margin: 0; color: var(--text-muted); font-size: 13px; line-height: 1.4; }

/* Form grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.grid-2 .span-2 { grid-column: span 2; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } .grid-2 .span-2 { grid-column: span 1; } }

/* ─────────────────────────────────────────────────────────────────────────
   Combobox (type-to-search + inline create)
   ───────────────────────────────────────────────────────────────────────── */
.combo {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r1);
  display: flex; gap: 6px; align-items: center; padding: 4px 6px 4px 12px;
}
.combo:focus-within { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); }
.combo .combo-input { flex: 1; border: none; padding: 8px 0; outline: none; font-family: inherit; font-size: 14px; background: transparent; min-width: 0; }
.combo.has-selection .combo-input { display: none; }
.combo .pill {
  display: flex; align-items: center; gap: var(--s2);
  background: var(--brand-50); color: var(--brand-700);
  padding: 4px 4px 4px 10px; border-radius: 6px; font-size: 13px;
}
.combo .pill .x { cursor: pointer; padding: 2px 6px; border-radius: 4px; color: var(--brand-600); }
.combo .pill .x:hover { background: var(--brand-100); }
.combo .actions { display: flex; gap: 4px; }
.combo .dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r2);
  box-shadow: var(--shadow-2);
  max-height: 320px; overflow-y: auto; z-index: 50;
}
.combo .dropdown.empty { display: none; }
.combo .dropdown-item {
  display: flex; gap: var(--s3); padding: 9px 12px;
  cursor: pointer; align-items: center; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.combo .dropdown-item:last-child { border-bottom: none; }
.combo .dropdown-item:hover, .combo .dropdown-item.highlighted { background: var(--brand-50); }
.combo .dropdown-item .body { flex: 1; min-width: 0; }
.combo .dropdown-item .sub { color: var(--text-muted); font-size: 12px; }
.combo .dropdown-item.create { background: var(--surface-2); color: var(--brand-700); font-weight: 500; }
.combo .dropdown-item.create:hover { background: var(--brand-50); }

.picker-row {
  display: grid; grid-template-columns: 1fr auto; gap: var(--s2);
  align-items: center; margin-bottom: var(--s2);
}
.picker-list { display: flex; flex-direction: column; gap: var(--s2); margin-bottom: var(--s3); }
.picker-list + .btn { align-self: flex-start; }

/* ─── Stat cards (dashboard) ─── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s4); margin-bottom: var(--s5); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r2); padding: var(--s4); }
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat-card .delta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ─── Detail view (contract/party/property) ─── */
.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: var(--s5); }
@media (max-width: 980px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-section { margin-bottom: var(--s5); }
.detail-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin: 0 0 var(--s3); font-weight: 600; }
.detail-section .card { padding: var(--s4); margin-bottom: var(--s3); }

/* ─── Modal / sheet ─── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4);
  display: flex; justify-content: center; align-items: flex-start; padding: 5vh var(--s4);
  z-index: 100; overflow-y: auto;
  animation: fadeIn 0.15s ease;
}
.modal-card {
  background: var(--surface); border-radius: var(--r3);
  width: 600px; max-width: 100%;
  box-shadow: var(--shadow-3);
  animation: slideUp 0.2s ease;
}
.modal-card.lg { width: 800px; }
.modal-header {
  padding: var(--s5) var(--s5) var(--s4);
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.modal-body { padding: var(--s5); max-height: 70vh; overflow-y: auto; }
.modal-footer {
  padding: var(--s4) var(--s5); border-top: 1px solid var(--border);
  display: flex; gap: var(--s2); justify-content: flex-end; align-items: center;
}
.modal-footer .error { margin-right: auto; color: var(--danger); font-size: 13px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ─── Toast notifications ─── */
.toasts { position: fixed; bottom: var(--s5); right: var(--s5); display: flex; flex-direction: column; gap: var(--s2); z-index: 200; pointer-events: none; }
.toast {
  background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: var(--r1);
  font-size: 13px; box-shadow: var(--shadow-3);
  animation: slideIn 0.2s ease; pointer-events: auto;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Skeleton loader ─── */
.skeleton {
  background: linear-gradient(90deg, #eef0f4 25%, #f6f7fb 50%, #eef0f4 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r1);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── Misc ─── */
.divider { height: 1px; background: var(--border); margin: var(--s5) 0; }
.flex-row { display: flex; align-items: center; gap: var(--s2); }
.flex-col { display: flex; flex-direction: column; gap: var(--s2); }
.between { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); }
.spacer { flex: 1; }
