/* Abogia Cloud — tema jurídico (variables de tenant en :root) */
@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Source+Serif+4:ital,opsz,wght@0,8..60,500;0,8..60,600;0,8..60,700;1,8..60,400&display=swap");

:root {
  --color-primary: #0F3D5E;
  --color-secondary: #1B6B93;
  --color-accent: #C4A35A;
  --color-bg: #F7F5F2;
  --color-surface: #FFFFFF;
  --color-text: #1A1A1A;
  --color-muted: #5C6670;
  --color-border: #E2DDD6;
  --color-danger: #B42318;
  --color-success: #1F6B4A;
  --color-warn: #9A6700;
  --font-heading: "Source Serif 4", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 61, 94, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 61, 94, 0.08);
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
  --header-h: 56px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --motion-fast: 180ms;
  --motion-med: 260ms;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background:
    radial-gradient(1200px 500px at 0% -10%, rgba(27, 107, 147, 0.08), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(196, 163, 90, 0.1), transparent 50%),
    var(--color-bg);
}
h1, h2, h3, h4, .brand-name, .page-title {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0 0 0.5rem;
}
a { color: var(--color-secondary); text-decoration: none; }
a:hover { color: var(--color-primary); text-decoration: underline; }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted, .text-sm { color: var(--color-muted); }
.text-sm { font-size: 0.85rem; }
.mb-0 { margin-bottom: 0; }
.spacer { flex: 1; }

/* ——— Auth ——— */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    linear-gradient(135deg, rgba(15, 61, 94, 0.92), rgba(27, 107, 147, 0.85)),
    var(--color-primary);
}
.auth-card {
  width: min(440px, 100%);
  background: var(--color-surface);
  border-radius: calc(var(--radius) + 4px);
  padding: 2rem 1.75rem 1.75rem;
  box-shadow: var(--shadow-md);
  animation: rise-in 0.45s var(--ease) both;
}
.auth-card .brand { text-align: center; margin-bottom: 1.25rem; }
.auth-card .brand-mark {
  width: 48px; height: 48px; margin: 0 auto 0.75rem;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--color-primary); color: #fff;
  font-family: var(--font-heading); font-size: 1.35rem; font-weight: 700;
}
.auth-card .brand-name { font-size: 1.45rem; margin: 0; }
.auth-card .brand-tag { color: var(--color-muted); font-size: 0.9rem; margin-top: 0.25rem; }
.auth-card h1 { font-size: 1.25rem; margin: 0 0 1rem; }
.auth-footer { text-align: center; margin: 1.25rem 0 0; font-size: 0.9rem; color: var(--color-muted); }

/* ——— Shell ——— */
.app-shell { display: flex; min-height: 100vh; position: relative; width: 100%; }
.app-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1rem 0.75rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.15rem;
  position: sticky; top: 0; height: 100vh; overflow: auto;
  z-index: 40;
  transition: width var(--motion-med) var(--ease), padding var(--motion-med) var(--ease);
}
.app-shell.sidebar-collapsed .app-sidebar {
  width: var(--sidebar-w-collapsed);
  padding-left: 0.45rem;
  padding-right: 0.45rem;
}
.app-shell.sidebar-collapsed .brand > div:last-child,
.app-shell.sidebar-collapsed .nav-section,
.app-shell.sidebar-collapsed .nav-link > :not(.nav-ico),
.app-shell.sidebar-collapsed .sidebar-foot { display: none; }
.app-shell.sidebar-collapsed .brand { justify-content: center; padding-left: 0.25rem; padding-right: 0.25rem; }
.app-shell.sidebar-collapsed .nav-link { justify-content: center; padding: 0.65rem 0.35rem; }
.app-shell.sidebar-collapsed .nav-ico { opacity: 1; font-size: 1.1rem; }
.app-sidebar .brand {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.65rem 1rem;
}
.brand-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--color-primary); color: #fff;
  display: grid; place-items: center;
  font-family: var(--font-heading); font-weight: 700;
}
.brand-name { font-size: 1.1rem; margin: 0; }
.brand-sub { font-size: 0.78rem; color: var(--color-muted); }
.nav-section {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--color-muted); padding: 0.85rem 0.65rem 0.35rem;
}
.nav-link {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.5rem 0.65rem; border-radius: var(--radius);
  color: var(--color-text); text-decoration: none;
  transition: background 0.15s var(--ease), color 0.15s;
}
.nav-link:hover { background: rgba(15, 61, 94, 0.06); text-decoration: none; }
.nav-link.active {
  background: rgba(15, 61, 94, 0.1);
  color: var(--color-primary);
  font-weight: 600;
}
.nav-ico { width: 1.25rem; text-align: center; opacity: 0.75; font-size: 0.95rem; }
.sidebar-foot {
  margin-top: auto; padding: 1rem 0.65rem 0.25rem;
  font-size: 0.75rem; color: var(--color-muted); line-height: 1.35;
}
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; width: 100%; }
.app-header {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem; gap: 1rem;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 30;
}
.header-left, .header-right { display: flex; align-items: center; gap: 0.75rem; }
.page-title { font-size: 1.15rem; margin: 0; }
.menu-toggle {
  display: none; border: 0; background: transparent; font-size: 1.25rem; cursor: pointer;
  padding: 0.35rem 0.5rem; border-radius: var(--radius);
}
.sidebar-collapse-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--color-border); background: var(--color-surface);
  width: 2rem; height: 2rem; border-radius: var(--radius); cursor: pointer;
  color: var(--color-primary); font-size: 0.95rem; line-height: 1;
  transition: background var(--motion-fast) var(--ease), transform var(--motion-fast) var(--ease);
}
.sidebar-collapse-btn:hover { background: rgba(15, 61, 94, 0.06); }
.app-shell.sidebar-collapsed .sidebar-collapse-btn { transform: rotate(180deg); }
.user-chip { text-align: right; line-height: 1.25; }
.app-content {
  padding: 1rem 1.25rem 1.5rem;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
}
.app-content.module-enter {
  animation: fade-up var(--motion-med) var(--ease) both;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15, 20, 25, 0.35); z-index: 35;
}
.module-fullbleed { min-height: calc(100vh - var(--header-h) - 2.5rem); display: flex; flex-direction: column; gap: 0.85rem; }
.toolbar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}

/* ——— Filters (compactos, aireados, todas las pestañas) ——— */
.filters-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.45rem 0 0.65rem;
  margin: 0 0 0.75rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 85%, transparent);
  border-radius: 0;
  container-type: inline-size;
  container-name: filters;
}
.filters-panel-compact {
  margin: 0;
  padding: 0.35rem 0.5rem 0.5rem;
  border: 0;
  background: transparent;
}
.filters-field {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  min-width: 0;
  margin: 0;
}
.filters-label {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-muted, #5a6570);
  line-height: 1.1;
}
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.55rem 0.7rem;
}
.filters-bar > .filters-field {
  flex: 0 1 auto;
}
.filters-field--search {
  flex: 1 1 200px;
  min-width: min(100%, 180px);
  max-width: 320px;
}
.filters-field--sm { flex: 0 1 118px; max-width: 140px; }
.filters-field--md { flex: 0 1 150px; max-width: 180px; }
.filters-field--lg { flex: 0 1 180px; max-width: 220px; }
.filters-field--date { flex: 0 1 132px; max-width: 148px; }
.filters-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
  margin-left: auto;
  padding-bottom: 0.1rem;
}
.filters-panel .filters-field .input,
.filters-panel .filters-field select.input,
.filters-panel .filters-field input.input {
  width: 100%;
  max-width: none;
  flex: none;
  min-height: 1.95rem;
  height: 1.95rem;
  padding: 0.28rem 0.45rem;
  font-size: 0.8rem;
  border-radius: calc(var(--radius) - 2px);
  background: var(--color-surface);
}
.filters-panel .btn-sm {
  min-height: 1.95rem;
  padding: 0.28rem 0.55rem;
  font-size: 0.78rem;
}
.filters-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.7rem;
  align-items: flex-end;
}
.filters-more {
  padding-top: 0.45rem;
  margin-top: 0.1rem;
  border-top: 1px dashed color-mix(in srgb, var(--color-border) 80%, transparent);
}
.filters-more[hidden] { display: none !important; }
.filters-count {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--color-muted, #5a6570);
  min-width: 4rem;
  text-align: right;
}
.filters-panel [data-filters-more][aria-expanded="true"] {
  color: var(--color-primary);
  font-weight: 600;
}

/* Expedientes: búsqueda un poco más ancha */
.filters-panel--matters .filters-field--search {
  flex: 1 1 220px;
  max-width: 280px;
}

@container filters (max-width: 720px) {
  .filters-field--search { max-width: none; flex: 1 1 100%; }
  .filters-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
}

/* Legacy row (fallback) */
.filters-row {
  display: flex; align-items: flex-end; gap: 0.55rem 0.7rem; flex-wrap: wrap;
}
.filters-row .input,
.filters-row input.input,
.filters-row select.input {
  min-width: 0; max-width: 200px; flex: 0 1 140px;
  min-height: 1.95rem; height: 1.95rem;
  padding: 0.28rem 0.45rem; font-size: 0.8rem;
}
.filters-row input[type="search"].input { flex: 1 1 180px; max-width: 280px; }
.filters-row input[type="date"].input,
.filters-row input[type="number"].input { flex: 0 1 132px; max-width: 148px; }
.filters-inline-label {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.18rem;
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--color-muted, #5a6570);
}
.filters-inline-label .input { flex: none; width: 132px; }
.invoice-filters {
  margin: 0 0 0.65rem;
  padding: 0.35rem 0 0.5rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 85%, transparent);
}


.tenant-banner {
  display: none; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.65rem 1.25rem;
  background: linear-gradient(90deg, rgba(196,163,90,0.2), rgba(15,61,94,0.08));
  border-bottom: 1px solid var(--color-border);
}
.tenant-banner.visible { display: flex; }
#tenant-switcher {
  min-width: 200px; padding: 0.35rem 0.55rem;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-surface);
}

/* ——— Components ——— */
.panel {
  background: var(--color-surface);
  border: 1px solid color-mix(in srgb, var(--color-border) 90%, transparent);
  border-radius: var(--radius);
  padding: 0.95rem 1.05rem;
  margin-bottom: 0.85rem;
  box-shadow: none;
}
.panel--flush-filters > .filters-panel {
  margin-top: 0.15rem;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.85rem;
}
.panel-header h2, .panel-header h3 { margin: 0; font-size: 1.1rem; }
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem; margin-bottom: 1rem;
}
.stats-grid-home {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  width: 100%;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  animation: fade-up var(--motion-med) var(--ease) both;
}
.stats-grid-home .stat-card:nth-child(1) { animation-delay: 0.02s; }
.stats-grid-home .stat-card:nth-child(2) { animation-delay: 0.06s; }
.stats-grid-home .stat-card:nth-child(3) { animation-delay: 0.1s; }
.stats-grid-home .stat-card:nth-child(4) { animation-delay: 0.14s; }
.stats-grid-home .stat-card:nth-child(5) { animation-delay: 0.18s; }
.stats-grid-home .stat-card:nth-child(6) { animation-delay: 0.22s; }
.stats-grid-home .stat-card:nth-child(7) { animation-delay: 0.26s; }
.stats-grid-home .stat-card:nth-child(8) { animation-delay: 0.3s; }
.stat-card .label { font-size: 0.8rem; color: var(--color-muted); }
.stat-card .value {
  font-family: var(--font-heading); font-size: 1.6rem; font-weight: 600;
  color: var(--color-primary); margin-top: 0.2rem;
}
.stat-card .hint {
  display: block; margin-top: 0.25rem;
  font-size: 0.75rem; color: var(--color-muted);
}
.stat-card.stat-warn .value { color: #b45309; }
.stat-card.stat-danger .value { color: #b91c1c; }
.home-dashboard { width: 100%; }
.home-panels {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem;
}
.home-panel { margin-bottom: 0; }
.home-deadline-table tr[data-matter] { cursor: pointer; }
.home-deadline-table tr[data-matter]:hover td { background: rgba(15, 61, 94, 0.04); }
.badge-overdue {
  display: inline-block; margin-left: 0.35rem;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em;
  color: #b91c1c; background: rgba(185, 28, 28, 0.1);
  border-radius: 999px; padding: 0.1rem 0.45rem; vertical-align: middle;
}
.disclaimer-bar {
  font-size: 0.82rem; color: var(--color-muted);
  background: rgba(196, 163, 90, 0.12);
  border: 1px solid rgba(196, 163, 90, 0.35);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin: 1rem 0;
}
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.5rem 0.95rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--color-primary); color: #fff;
  cursor: pointer; font-weight: 500;
  transition: transform 0.12s var(--ease), background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--color-secondary); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn-ghost {
  background: transparent; color: var(--color-primary);
  border-color: var(--color-border);
}
.btn-ghost:hover { background: rgba(15, 61, 94, 0.06); color: var(--color-primary); }
.btn-accent { background: var(--color-accent); color: #1a1a1a; }
.btn-accent:hover { filter: brightness(1.05); color: #1a1a1a; }
.btn-danger { background: var(--color-danger); }
.form-row { margin-bottom: 0.85rem; }
.form-row label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.3rem; }
.form-row input, .form-row select, .form-row textarea, .input {
  width: 100%; padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-surface);
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus, .input:focus {
  outline: 2px solid rgba(27, 107, 147, 0.35); border-color: var(--color-secondary);
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem 1rem;
}
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.alert {
  padding: 0.75rem 0.9rem; border-radius: var(--radius); margin-bottom: 0.85rem; font-size: 0.92rem;
}
.alert-error { background: rgba(180, 35, 24, 0.08); border: 1px solid rgba(180, 35, 24, 0.3); color: var(--color-danger); }
.alert-warn { background: rgba(154, 103, 0, 0.1); border: 1px solid rgba(154, 103, 0, 0.3); color: var(--color-warn); }
.alert-success { background: rgba(31, 107, 74, 0.1); border: 1px solid rgba(31, 107, 74, 0.3); color: var(--color-success); }
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--color-muted); }
.empty-state h3 { color: var(--color-text); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td {
  text-align: left; padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--color-border); vertical-align: top;
}
table.data th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); }
table.data tr:hover td { background: rgba(15, 61, 94, 0.03); }
.list-item {
  padding: 0.48rem 0.65rem; border: 1px solid color-mix(in srgb, var(--color-border) 88%, transparent);
  border-radius: calc(var(--radius) - 2px); margin-bottom: 0.3rem; cursor: pointer;
  background: var(--color-surface); transition: border-color 0.15s, box-shadow 0.15s;
}
.list-item:hover { border-color: var(--color-secondary); }
.list-item.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}
.list-item .meta { font-size: 0.75rem; color: var(--color-muted); margin-top: 0.12rem; }
.list-item.no-click { cursor: default; }
.split, .split-view {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 0.85rem;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}
.split-list {
  overflow: auto;
  max-height: calc(100vh - var(--header-h) - 5.5rem);
  padding: 0.35rem 0.15rem 0.35rem 0;
}
.clients-preview { min-height: 280px; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 0.65rem; border-bottom: 1px solid var(--color-border); }
.tab {
  border: 0; background: transparent; padding: 0.55rem 0.85rem; cursor: pointer;
  color: var(--color-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: tab-in var(--motion-med) var(--ease) both; }
.color-fields {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem;
}
.color-fields-lg {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem 1.25rem;
  margin: 1rem 0 1.25rem;
}
.color-picker-field label {
  display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.4rem;
}
.color-picker-control {
  display: flex; flex-direction: column; gap: 0.45rem;
}
.color-swatch {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 60px;
  padding: 0; border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) + 2px);
  background: transparent; cursor: pointer;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.color-swatch:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.color-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch::-webkit-color-swatch { border: 0; border-radius: calc(var(--radius) + 1px); }
.color-swatch::-moz-color-swatch { border: 0; border-radius: calc(var(--radius) + 1px); }
.color-hex {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem; letter-spacing: 0.02em; text-transform: uppercase;
}
.theme-preview {
  margin: 1rem 0; border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden;
  transition: box-shadow var(--motion-med) var(--ease);
}
.theme-preview-bar {
  background: var(--preview-primary, var(--color-primary)); color: #fff;
  padding: 0.85rem 1rem; font-weight: 600;
  transition: background var(--motion-fast) linear;
}
.theme-preview-body {
  background: var(--preview-bg, var(--color-bg)); padding: 1.1rem;
  transition: background var(--motion-fast) linear;
}
.theme-preview-card {
  background: var(--preview-surface, var(--color-surface));
  color: var(--preview-text, var(--color-text));
  border-radius: var(--preview-radius, var(--radius));
  padding: 1rem; border: 1px solid var(--color-border);
  transition: background var(--motion-fast) linear, color var(--motion-fast) linear, border-radius var(--motion-fast) linear;
}
.theme-preview-btn {
  display: inline-block; margin-top: 0.75rem; padding: 0.45rem 0.9rem;
  background: var(--preview-accent, var(--color-accent));
  border-radius: var(--preview-radius, var(--radius));
  font-size: 0.85rem;
  transition: background var(--motion-fast) linear, border-radius var(--motion-fast) linear;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--color-border); border-top-color: var(--color-secondary);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}

/* Modal / toast */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 20, 25, 0.45);
  display: none; place-items: center; z-index: 80; padding: 1rem;
}
.modal-backdrop.open { display: grid; }
.modal {
  width: min(560px, 100%); max-height: 90vh; overflow: auto;
  background: var(--color-surface); border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-md); padding: 1.1rem 1.2rem 1.25rem;
  animation: rise-in 0.25s var(--ease);
}
.modal.modal-lg { width: min(820px, 100%); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem;
}
.matter-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem 1rem;
  margin: 0.25rem 0 1rem;
}
.matter-meta-item {
  display: flex; flex-direction: column; gap: 0.15rem;
  min-width: 0;
}
.matter-meta-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-muted); font-weight: 600;
}
.matter-meta-value {
  font-size: 0.92rem; color: var(--color-text);
  word-break: break-word;
}
.matter-notes {
  padding: 0.75rem 0.85rem;
  background: rgba(15, 61, 94, 0.03);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}
.matter-panel-list {
  margin: 0; padding-left: 1.15rem;
}
.matter-panel-list li { margin-bottom: 0.4rem; }
.matter-panel-list .meta {
  font-size: 0.8rem; color: var(--color-muted); margin-top: 0.15rem;
}
.context-pack-readable h4 {
  margin: 1rem 0 0.45rem; font-size: 0.95rem;
}
.context-pack-json {
  margin-top: 1rem;
  border-top: 1px solid var(--color-border);
  padding-top: 0.65rem;
}
.context-pack-json summary {
  cursor: pointer; font-size: 0.88rem; color: var(--color-secondary); font-weight: 500;
}
.context-pack-pre {
  white-space: pre-wrap;
  font-size: 0.78rem;
  max-height: 40vh;
  overflow: auto;
  margin: 0.5rem 0 0;
  padding: 0.65rem;
  background: rgba(15, 61, 94, 0.04);
  border-radius: var(--radius);
}
.modal-close {
  border: 0; background: transparent; font-size: 1.4rem; cursor: pointer; line-height: 1; color: var(--color-muted);
}
.toast-host {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 90;
  display: flex; flex-direction: column; gap: 0.5rem; max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  background: var(--color-primary); color: #fff; padding: 0.7rem 0.95rem;
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  animation: rise-in 0.25s var(--ease); transition: opacity 0.25s;
}
.toast.error { background: var(--color-danger); }
.toast.warn { background: var(--color-warn); }
.toast.success { background: var(--color-success); }

/* Chat */
.chat-layout {
  display: grid; grid-template-columns: 260px 1fr; gap: 0;
  min-height: calc(100vh - var(--header-h) - 3rem);
  border: 1px solid var(--color-border); border-radius: calc(var(--radius) + 2px);
  overflow: hidden; background: var(--color-surface);
}
.chat-sidebar { border-right: 1px solid var(--color-border); display: flex; flex-direction: column; }
.chat-sidebar-head { padding: 0.75rem; border-bottom: 1px solid var(--color-border); }
.chat-conv-list { overflow: auto; flex: 1; padding: 0.5rem; }
.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-toolbar {
  display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap;
  padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--color-border);
  background: rgba(247, 245, 242, 0.65);
}
.chat-messages {
  flex: 1; overflow: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.65rem;
  background:
    linear-gradient(180deg, rgba(247,245,242,0.5), transparent 120px),
    var(--color-surface);
}
.msg {
  max-width: min(720px, 92%); padding: 0.7rem 0.9rem; border-radius: 12px;
  white-space: pre-wrap; word-break: break-word; line-height: 1.45;
}
.msg.user {
  align-self: flex-end; background: var(--color-primary); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant, .msg.system {
  align-self: flex-start; background: #F1EEE8; border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}
.msg.system { font-size: 0.88rem; color: var(--color-muted); }
.streaming-cursor::after {
  content: "▍ animation: blink 0.9s step-end infinite; margin-left: 2px;
}
.chat-composer {
  display: flex; gap: 0.65rem; padding: 0.75rem; border-top: 1px solid var(--color-border);
  align-items: flex-end;
}
.chat-composer textarea {
  flex: 1; resize: vertical; min-height: 52px; max-height: 160px;
  border: 1px solid var(--color-border); border-radius: var(--radius); padding: 0.55rem 0.7rem;
}
.approval-card {
  border: 1px solid rgba(154, 103, 0, 0.4); background: rgba(251, 191, 36, 0.1);
  border-radius: var(--radius); padding: 0.75rem; margin-top: 0.5rem;
}
.approval-card .actions { display: flex; gap: 0.5rem; margin-top: 0.55rem; }

/* ——— Client sheet (full viewport) ——— */
.client-sheet {
  position: fixed; inset: 0; z-index: 70;
  background: var(--color-bg);
  display: flex; flex-direction: column;
  animation: fade-in var(--motion-med) var(--ease) both;
}
.client-sheet[hidden] { display: none !important; }
.client-sheet-inner {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0; width: 100%;
  background:
    radial-gradient(900px 320px at 0% 0%, rgba(27, 107, 147, 0.07), transparent 55%),
    radial-gradient(700px 280px at 100% 0%, rgba(196, 163, 90, 0.1), transparent 50%),
    var(--color-bg);
}
.client-sheet-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: 1.1rem 1.5rem 0.85rem;
  border-bottom: 1px solid var(--color-border);
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(8px);
}
.client-sheet-eyebrow {
  margin: 0; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--color-muted);
}
.client-sheet-heading h2 { margin: 0.15rem 0 0.2rem; font-size: 1.45rem; color: var(--color-primary); }
.client-sheet-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.client-sheet-tabs {
  padding: 0 1.5rem; margin: 0;
  background: rgba(255,255,255,0.5);
}
.client-sheet-body {
  flex: 1; min-height: 0; overflow: auto;
  padding: 1.25rem 1.5rem 2rem;
}
.sheet-panel { display: none; }
.sheet-panel.active { display: block; animation: tab-in var(--motion-med) var(--ease) both; }
.sheet-section-title {
  margin: 1.25rem 0 0.75rem; font-size: 1rem; color: var(--color-primary);
  border-bottom: 1px solid var(--color-border); padding-bottom: 0.35rem;
}
.sheet-panel-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.85rem;
}
.form-row-span { grid-column: 1 / -1; }
.client-sheet-form .form-grid { margin-bottom: 0.25rem; }
.contacts-editor { display: flex; flex-direction: column; gap: 0.75rem; }
.contact-card {
  border: 1px solid var(--color-border); border-radius: calc(var(--radius) + 2px);
  padding: 0.9rem 1rem; background: var(--color-surface);
  animation: fade-up var(--motion-fast) var(--ease) both;
}
.contact-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; margin-bottom: 0.65rem;
}
.contact-card-head strong { color: var(--color-primary); }
.tag-chip {
  display: inline-block; font-size: 0.72rem; padding: 0.15rem 0.45rem;
  border-radius: 4px; margin: 0 0.2rem 0.2rem 0;
  background: rgba(15, 61, 94, 0.08); color: var(--color-primary);
}
.lifecycle-badge {
  display: inline-block; font-size: 0.75rem; padding: 0.15rem 0.5rem;
  border-radius: 999px; background: rgba(196, 163, 90, 0.18); color: #6b5320;
}
.overview-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem; margin-top: 0.5rem;
}
.overview-block { margin-bottom: 0; }
.overview-block h3 { font-size: 1rem; margin: 0 0 0.65rem; }
.interactions-list .list-item { margin-bottom: 0.55rem; }
.kind-pill {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 0.12rem 0.45rem; border-radius: 4px;
  background: rgba(27, 107, 147, 0.12); color: var(--color-secondary);
  text-transform: capitalize;
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes tab-in {
  from { opacity: 0; transform: translateX(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 960px) {
  .app-sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-105%);
    transition: transform 0.25s var(--ease); box-shadow: var(--shadow-md);
    width: var(--sidebar-w) !important;
  }
  .app-shell.sidebar-open .app-sidebar { transform: none; }
  .app-shell.sidebar-open .sidebar-backdrop { display: block; }
  .menu-toggle { display: inline-flex; }
  .sidebar-collapse-btn { display: none; }
  .split, .split-view { grid-template-columns: 1fr; }
  .split-list { max-height: 40vh; }
  .overview-grid { grid-template-columns: 1fr; }
  .client-sheet-header, .client-sheet-tabs, .client-sheet-body { padding-left: 1rem; padding-right: 1rem; }
  .chat-layout { grid-template-columns: 1fr; height: auto; min-height: 70vh; }
  .chat-sidebar { max-height: 220px; border-right: 0; border-bottom: 1px solid var(--color-border); }
  .app-content { padding: 0.85rem; }
  .home-panels { grid-template-columns: 1fr; }
}

@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;
  }
}
