:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #15211f;
  --muted: #66736f;
  --line: #dce5e2;
  --brand: #11858d;
  --brand-dark: #0c6268;
  --accent: #c99636;
  --soft: #f6ecd9;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: grid;
  grid-template-columns: 260px 1fr;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 32px; }
h2 { margin-bottom: 0; font-size: 18px; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #11858d 0%, #11858d 48%, #ffffff 48%);
}

.login-screen.hidden { display: none; }

.login-card {
  width: min(460px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
  padding: 26px;
}

.login-brand { margin-bottom: 22px; color: var(--ink); }
.login-card p { color: var(--muted); }
.login-form { display: grid; gap: 13px; padding: 0; }
.form-error { min-height: 18px; color: var(--danger); font-size: 13px; font-weight: 700; }

.credentials {
  display: none;
  gap: 6px;
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  background: var(--soft);
  font-size: 13px;
}

.app-only { visibility: hidden; }
body.logged-in .app-only { visibility: visible; }

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  height: 100vh;
  overflow-y: auto;
  padding: 24px;
  background: #11858d;
  color: #f7fbfa;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: contain;
  background: white;
  padding: 5px;
  border: 1px solid rgba(201, 150, 54, .35);
}
.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--brand-dark);
  font-weight: 900;
}
.brand strong, .brand span { display: block; }
.brand span, .sidebar-note span, .muted { color: var(--muted); font-size: 13px; }
.sidebar .brand span, .sidebar-note span { color: rgba(255,255,255,.82); }

.nav { display: grid; gap: 8px; }
.nav button {
  min-height: 44px;
  text-align: left;
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
  color: white;
}
.nav button.active, .nav button:hover { background: rgba(255,255,255,.18); color: white; }

.sidebar-note {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 8px;
}
.sidebar-note strong { display: block; margin: 6px 0 12px; }
.sidebar-link { padding: 0; background: transparent; color: white; font-weight: 800; }

.shell { padding: 28px; overflow: hidden; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 24px;
}
.eyebrow { margin: 0 0 4px; color: var(--brand); font-size: 13px; font-weight: 700; text-transform: uppercase; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 11px 12px;
}
#searchInput { width: min(360px, 34vw); }

.primary, .ghost, .action-link {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 15px;
  font-weight: 700;
}
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-dark); }
.ghost { background: var(--soft); color: var(--brand-dark); }
.action-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  text-decoration: none;
  background: var(--soft);
  color: var(--brand-dark);
  font-size: 13px;
}

.view { display: none; }
.view.active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metrics article, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metrics article { padding: 18px; }
.metrics span { color: var(--muted); font-size: 13px; }
.metrics strong { display: block; margin-top: 8px; font-size: 28px; }

.workgrid, .calendar-layout, .communication-layout, .center-account-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, .8fr);
  gap: 18px;
}
.panel { padding: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }

.pipeline {
  display: grid;
  grid-template-columns: repeat(5, minmax(170px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.stage { background: #f7faf9; border: 1px solid var(--line); border-radius: 8px; min-height: 300px; padding: 10px; }
.stage h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); }

.lead-card, .task, .case-item, .appointment, .doc-row, .call-item, .team-card, .day-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}
.lead-card { display: grid; gap: 8px; padding: 12px; border-left: 4px solid var(--brand); margin-bottom: 10px; background: white; }
.lead-card strong { font-size: 15px; }
.tag, .status {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 9px;
  background: #fff4df;
  color: #7a4c10;
  font-size: 12px;
  font-weight: 800;
}
.status { background: var(--soft); color: var(--brand-dark); }

.task-list, .case-list, .appointment-list, .checklist, .call-list, .team-list, .expense-list, .summary-list, .center-account-list, .rate-list, .card-list { display: grid; gap: 10px; }
.task { display: grid; gap: 5px; padding: 12px; }
.task time { color: var(--accent); font-size: 13px; font-weight: 700; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 13px; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.danger-button {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 10px;
  background: #ffe8e5;
  color: var(--danger);
  font-weight: 900;
}
.case-layout { display: grid; grid-template-columns: minmax(280px, .9fr) minmax(320px, 1.1fr); gap: 18px; }
.case-item { display: grid; gap: 6px; text-align: left; padding: 12px; }
.case-item.active { outline: 2px solid var(--brand); background: var(--soft); }
.doc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; }
.doc-row button { width: 34px; height: 34px; border-radius: 8px; background: var(--soft); color: var(--brand-dark); font-weight: 900; }
.doc-row.missing { border-color: #f0b8b2; }
.doc-row.missing button { background: #ffe8e5; color: var(--danger); }

.calendar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.calendar-controls > .ghost {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 20px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.segmented button {
  min-height: 38px;
  padding: 0 12px;
  background: white;
  color: var(--muted);
  font-weight: 800;
}

.segmented button.active {
  background: var(--brand);
  color: white;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  overflow-x: auto;
}
.calendar-grid.week-view {
  grid-template-columns: repeat(7, minmax(150px, 1fr));
}
.day-card { min-height: 170px; padding: 10px; }
.day-card.outside-month { opacity: .45; }
.day-card header { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.day-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 8px;
}
.day-actions button {
  min-height: 30px;
  border-radius: 8px;
  background: white;
  color: var(--brand-dark);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}
.calendar-event {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  margin-bottom: 8px;
  padding: 8px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  font-size: 13px;
}
.calendar-event strong { color: var(--brand-dark); }

.appointment { display: grid; grid-template-columns: 124px 1fr auto; gap: 12px; align-items: center; padding: 12px; }
.appointment time { color: var(--brand-dark); font-weight: 800; }

.call-item { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 12px; }
.call-item time { color: var(--accent); font-weight: 800; }
.call-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.integration-box { display: grid; gap: 8px; color: var(--muted); line-height: 1.45; }
.integration-box strong { color: var(--ink); }
.team-card { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; padding: 14px; align-items: center; }
.team-card code { padding: 5px 8px; border-radius: 8px; background: #f0f3f2; }
.locked-panel.hidden, #accountingContent.hidden, #officeContent.hidden { display: none; }
.profit-total {
  color: var(--brand-dark);
  background: var(--soft);
  border-radius: 8px;
  padding: 10px 12px;
}
.accounting-table input,
.accounting-table select {
  min-width: 110px;
  padding: 8px;
}
.profit-positive { color: #087443; font-weight: 900; }
.profit-negative { color: var(--danger); font-weight: 900; }
.process-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 12px;
  overflow-x: auto;
}
.process-column {
  min-height: 280px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
}
.process-column h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
}
.process-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: white;
}
.office-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr);
  gap: 18px;
}
.inline-form {
  display: grid;
  grid-template-columns: 1fr 150px 90px auto;
  gap: 10px;
  padding: 0;
  margin-bottom: 14px;
}
.expense-row,
.summary-card {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfc;
}
.summary-card {
  grid-template-columns: 40px 1fr;
}
.summary-card strong {
  display: block;
}
.center-account-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr)) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfc;
}
.account-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}
.country-group {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfc;
}
.country-group h3 {
  margin: 0;
  font-size: 16px;
  color: var(--brand-dark);
}
.center-account-card span,
.center-account-card strong {
  display: block;
}
.rate-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfc;
}
.payment-card {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, minmax(110px, 1fr)) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfc;
}
.payment-card span,
.payment-card strong {
  display: block;
}
.security-note {
  margin-bottom: 16px;
  padding: 12px;
  border-radius: 8px;
  background: #fff4df;
  color: #7a4c10;
  font-weight: 800;
  font-size: 13px;
}
button:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.context-menu {
  position: fixed;
  z-index: 50;
  display: none;
  min-width: 170px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 18px 46px rgba(0,0,0,.16);
}
.context-menu.open { display: grid; }
.context-menu button {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 10px;
  text-align: left;
  background: white;
  color: var(--ink);
  font-weight: 800;
}
.context-menu button:hover { background: var(--soft); }
.context-menu button:disabled { opacity: .45; cursor: not-allowed; }

dialog {
  width: min(760px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .24);
}
dialog::backdrop { background: rgba(16, 37, 34, .52); }
form { padding: 22px; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.icon-button { width: 36px; height: 36px; border-radius: 8px; background: #f0f3f2; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 18px 0 12px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.full { margin-bottom: 16px; }

@media (max-width: 1100px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; min-height: auto; height: auto; }
  .nav { grid-template-columns: repeat(10, minmax(118px, 1fr)); overflow-x: auto; }
  .sidebar-note { display: none; }
  .metrics, .workgrid, .case-layout, .calendar-layout, .communication-layout, .office-layout, .center-account-layout { grid-template-columns: 1fr; }
  .topbar { align-items: stretch; flex-direction: column; }
  .topbar-actions { align-items: stretch; flex-direction: column; }
  #searchInput { width: 100%; }
}

@media (max-width: 640px) {
  .shell, .sidebar { padding: 18px; }
  .form-grid, .appointment, .call-item, .team-card, .inline-form, .expense-row, .center-account-card, .payment-card { grid-template-columns: 1fr; }
  h1 { font-size: 26px; }
}
