/* ── Legal Matter Management ── */
:root {
  --ld-accent: #7c3aed;
  --ld-accent-soft: rgba(124, 58, 237, 0.14);
  --ld-bg: #0B1729;
  --ld-navy: #112240;
  --ld-mid: #1A3355;
  --ld-line: rgba(124, 58, 237, 0.18);
  --ld-text: #E6EDF7;
  --ld-muted: #8899AA;
  --ld-dim: #566980;
  --ld-red: #ef4444;
  --ld-amber: #f59e0b;
  --ld-green: #34d399;
  --ld-orange: #fb923c;
}

/* View container */
#legal-view {
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  background: var(--ld-bg);
  color: var(--ld-text);
}

/* Body */
.ld-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 24px;
  display: flex;
  flex-direction: column;
}

/* Topbar + tab strip */
.ld-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--ld-line);
  background: var(--ld-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.ld-topbar-left { display: flex; flex-direction: column; }
.ld-topbar-eyebrow {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: var(--ld-accent);
  margin-bottom: 1px;
}
.ld-topbar-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ld-text);
}
.ld-topbar-right { display: flex; align-items: center; gap: 8px; }

.ld-tab-strip {
  display: flex;
  gap: 2px;
  background: rgba(124, 58, 237, 0.07);
  border: 1px solid rgba(124, 58, 237, 0.18);
  border-radius: 8px;
  padding: 2px;
}
.ld-tab {
  background: transparent;
  border: none;
  color: var(--ld-muted);
  border-radius: 6px;
  padding: 4px 14px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.ld-tab:hover { color: var(--ld-text); }
.ld-tab.active {
  background: var(--ld-accent);
  color: #0B1729;
  font-weight: 600;
}

/* Content area */
.ld-content {
  padding: 12px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* States */
.ld-loading, .ld-error {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--ld-muted);
  font-size: 0.875rem;
}
.ld-error { color: var(--ld-red); }
.ld-empty { color: var(--ld-dim); font-size: 0.78rem; padding: 12px 4px; }

/* KPIs */
.ld-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.ld-kpi {
  background: var(--ld-navy);
  border: 1px solid var(--ld-line);
  border-radius: 10px;
  padding: 12px 14px;
}
.ld-kpi-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--ld-text);
  line-height: 1.1;
  margin-bottom: 2px;
}
.ld-kpi-label {
  font-size: 0.7rem;
  color: var(--ld-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ld-kpi-red   .ld-kpi-value { color: var(--ld-red); }
.ld-kpi-amber .ld-kpi-value { color: var(--ld-amber); }

/* Sections */
.ld-section {
  background: var(--ld-navy);
  border: 1px solid var(--ld-line);
  border-radius: 10px;
  padding: 12px 14px;
}
.ld-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.ld-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ld-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ld-count {
  background: var(--ld-mid);
  color: var(--ld-accent);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 0.65rem;
  font-weight: 700;
}

/* Cards */
.ld-card {
  background: var(--ld-mid);
  border: 1px solid var(--ld-line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.ld-card:hover { background: rgba(124, 58, 237, 0.12); border-color: var(--ld-accent); }
.ld-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.ld-card-name { font-weight: 600; color: var(--ld-text); font-size: 0.85rem; }
.ld-card-meta { font-size: 0.7rem; color: var(--ld-dim); font-family: ui-monospace, monospace; }
.ld-card-sub { font-size: 0.72rem; color: var(--ld-muted); }
.ld-card-summary { font-size: 0.78rem; color: var(--ld-text); margin-top: 6px; }

/* Row items for feeds (tasks, deadlines) */
.ld-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 7px;
  background: var(--ld-mid);
  margin-bottom: 4px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.12s;
}
.ld-row:hover { background: rgba(124, 58, 237, 0.12); }
.ld-row-matter { font-weight: 600; color: var(--ld-text); flex-shrink: 0; min-width: 0; }
.ld-row-text { color: var(--ld-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ld-row-meta { color: var(--ld-dim); font-family: ui-monospace, monospace; font-size: 0.68rem; flex-shrink: 0; }

/* Tables */
.ld-table-scroll { overflow-x: auto; }
.ld-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}
.ld-table th {
  padding: 6px 8px;
  text-align: left;
  color: var(--ld-muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--ld-line);
  white-space: nowrap;
  user-select: none;
}
.ld-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--ld-line);
  color: var(--ld-text);
}
.ld-table tbody tr { cursor: pointer; transition: background 0.1s; }
.ld-table tbody tr:hover { background: rgba(124, 58, 237, 0.07); }
.ld-table .al-r { text-align: right; }
.ld-table .al-c { text-align: center; }
.ld-td-name { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ld-td-actions { white-space: nowrap; }

/* Status badge */
.ld-status {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
}
.ld-status-active                { background: rgba(52,211,153,0.18); color: var(--ld-green); }
.ld-status-closed                { background: rgba(136,153,170,0.18); color: var(--ld-muted); }
.ld-status-under-review          { background: rgba(245,158,11,0.18); color: var(--ld-amber); }
.ld-status-active--waiting-ned   { background: rgba(251,146,60,0.18); color: var(--ld-orange); }
.ld-status-active--waiting-oren  { background: rgba(251,146,60,0.18); color: var(--ld-orange); }
.ld-status-active--waiting-cp    { background: rgba(251,146,60,0.18); color: var(--ld-orange); }
.ld-status-on-hold               { background: rgba(136,153,170,0.18); color: var(--ld-muted); }

/* Priority badge */
.ld-priority {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
}
.ld-priority-high   { background: rgba(239,68,68,0.18); color: var(--ld-red); }
.ld-priority-normal { background: rgba(136,153,170,0.14); color: var(--ld-muted); }
.ld-priority-low    { background: rgba(136,153,170,0.1);  color: var(--ld-dim); }

/* Urgency badge for tasks (!!, !, -) */
.ld-urg {
  display: inline-block;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.7rem;
}
.ld-urg-high { background: rgba(239,68,68,0.18); color: var(--ld-red); }
.ld-urg-med  { background: rgba(245,158,11,0.18); color: var(--ld-amber); }
.ld-urg-low  { color: var(--ld-dim); background: transparent; }

/* Buttons */
.ld-btn {
  background: var(--ld-mid);
  border: 1px solid var(--ld-line);
  color: var(--ld-text);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.ld-btn:hover { background: rgba(124, 58, 237, 0.12); border-color: var(--ld-accent); color: var(--ld-accent); }
.ld-btn-sm { padding: 3px 8px; font-size: 0.7rem; }
.ld-btn-primary {
  background: var(--ld-accent);
  border-color: var(--ld-accent);
  color: #0B1729;
  font-weight: 600;
}
.ld-btn-primary:hover { background: #8b4ff0; border-color: #8b4ff0; color: #0B1729; }
.ld-btn-ghost { background: transparent; }
.ld-btn-danger {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--ld-red);
}
.ld-btn-danger:hover { background: rgba(239,68,68,0.15); border-color: var(--ld-red); color: var(--ld-red); }

/* Back button */
.ld-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--ld-muted);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 4px 2px;
  margin-bottom: 6px;
}
.ld-back-btn:hover { color: var(--ld-accent); }

/* Filter bar */
.ld-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: var(--ld-navy);
  border: 1px solid var(--ld-line);
  border-radius: 8px;
}
.ld-filter-bar .ld-input,
.ld-filter-bar .ld-select {
  min-width: 140px;
}

/* Form inputs */
.ld-form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.ld-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 480px) { .ld-form-grid { grid-template-columns: 1fr; } }
.ld-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ld-muted);
  font-weight: 600;
}
.ld-input, .ld-select, .ld-textarea {
  background: var(--ld-bg);
  border: 1px solid var(--ld-line);
  color: var(--ld-text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.12s;
}
.ld-input:focus, .ld-select:focus, .ld-textarea:focus {
  border-color: var(--ld-accent);
}
.ld-textarea { min-height: 70px; resize: vertical; }

/* Detail view */
.ld-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: var(--ld-navy);
  border: 1px solid var(--ld-line);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.ld-detail-title { font-size: 1.1rem; font-weight: 700; color: var(--ld-text); margin-bottom: 4px; }
.ld-detail-meta  { font-size: 0.72rem; color: var(--ld-muted); display: flex; gap: 10px; flex-wrap: wrap; }
.ld-detail-meta span { white-space: nowrap; }

.ld-detail-tabs {
  display: flex;
  gap: 2px;
  background: rgba(124, 58, 237, 0.07);
  border: 1px solid rgba(124, 58, 237, 0.18);
  border-radius: 8px;
  padding: 2px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.ld-detail-tab {
  background: transparent;
  border: none;
  color: var(--ld-muted);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ld-detail-tab:hover { color: var(--ld-text); }
.ld-detail-tab.active {
  background: var(--ld-accent);
  color: #0B1729;
  font-weight: 600;
}

.ld-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.ld-detail-cell {
  background: var(--ld-mid);
  border-radius: 8px;
  padding: 9px 11px;
}
.ld-detail-cell-label {
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ld-dim);
  margin-bottom: 3px;
}
.ld-detail-cell-value {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ld-text);
  overflow-wrap: anywhere;
}
.ld-detail-cell-value a { color: var(--ld-accent); text-decoration: none; }
.ld-detail-cell-value a:hover { text-decoration: underline; }

.ld-detail-summary {
  background: var(--ld-mid);
  border-radius: 8px;
  padding: 11px 13px;
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--ld-text);
  line-height: 1.45;
  white-space: pre-wrap;
}

/* Activity timeline */
.ld-activity {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ld-activity-item {
  display: flex;
  gap: 10px;
  background: var(--ld-mid);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 0.78rem;
}
.ld-activity-date {
  flex-shrink: 0;
  width: 90px;
  color: var(--ld-dim);
  font-family: ui-monospace, monospace;
  font-size: 0.68rem;
  padding-top: 1px;
}
.ld-activity-body { flex: 1; color: var(--ld-text); }
.ld-activity-type {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ld-accent);
  margin-right: 6px;
  letter-spacing: 0.05em;
}
.ld-activity-author { color: var(--ld-muted); font-size: 0.68rem; margin-top: 2px; }

/* Modal */
.ld-modal {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.ld-modal.hidden { display: none; }
.ld-modal-inner {
  position: relative;
  background: var(--ld-navy);
  border: 1px solid var(--ld-line);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  padding: 20px 22px;
}
.ld-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 1;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--ld-mid);
  border: 1px solid var(--ld-line);
  color: var(--ld-muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ld-modal-close:hover { color: var(--ld-accent); border-color: var(--ld-accent); }
.ld-modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ld-text);
  margin: 0 0 12px;
}
.ld-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* Settings */
.ld-settings-group {
  background: var(--ld-navy);
  border: 1px solid var(--ld-line);
  border-radius: 10px;
  padding: 12px 14px;
}
.ld-settings-group h4 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--ld-text);
  font-weight: 600;
}
.ld-type-list { display: flex; flex-direction: column; gap: 4px; }
.ld-type-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: var(--ld-mid);
  border-radius: 6px;
  font-size: 0.78rem;
}
.ld-type-item.inactive { opacity: 0.5; }
.ld-type-item .ld-type-actions { display: flex; gap: 6px; }

/* Lien position badge */
.ld-lien { color: var(--ld-muted); font-family: ui-monospace, monospace; font-size: 0.72rem; }

/* Doc list */
.ld-docs { display: flex; flex-direction: column; gap: 4px; }
.ld-doc-link {
  display: block;
  padding: 7px 10px;
  background: var(--ld-mid);
  border-radius: 6px;
  color: var(--ld-accent);
  text-decoration: none;
  font-size: 0.78rem;
  word-break: break-all;
}
.ld-doc-link:hover { background: rgba(124, 58, 237, 0.15); }

/* Narrow screens: section cards stack naturally; tables scroll horizontally. */
@media (max-width: 520px) {
  .ld-topbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .ld-tab-strip { overflow-x: auto; }
}
