:root {
  --primary: #0f4c81;
  --primary-strong: #0a3860;
  --secondary: #001e3d;
  --ink: #102033;
  --muted: #64748b;
  --soft: #eef4fb;
  --bg: #f7fafc;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --line: #d8e1ec;
  --good: #16a34a;
  --good-soft: #e8f7ee;
  --warn: #d97706;
  --warn-soft: #fff3db;
  --bad: #dc2626;
  --bad-soft: #fdeaea;
  --violet: #7c3aed;
  --violet-soft: #f1eafe;
  --shadow: 0 18px 40px rgba(16, 32, 51, 0.12);
  --radius: 8px;
  --sidebar-width: 260px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 76, 129, 0.06), rgba(255, 255, 255, 0) 280px),
    var(--bg);
}

body.theme-dark {
  --ink: #edf5ff;
  --muted: #a9b8c9;
  --soft: #10243a;
  --bg: #07131f;
  --surface: #0d1b2a;
  --surface-raised: #13263a;
  --line: #254058;
  --shadow: 0 20px 52px rgba(0, 0, 0, 0.35);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: var(--secondary);
  color: #f8fbff;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f4c81, #1a9988);
  color: #fff;
  font-weight: 800;
}

.brand-title {
  display: block;
  font-weight: 800;
  font-size: 17px;
}

.brand-subtitle {
  display: block;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
  margin-top: 2px;
}

.nav-section {
  display: grid;
  gap: 6px;
}

.nav-label {
  padding: 0 8px;
  color: rgba(255, 255, 255, 0.52);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
}

.nav-link {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.78);
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
}

.nav-link:active {
  transform: translateY(1px);
}

.nav-icon {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 800;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 10px;
}

.workspace-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--secondary);
  font-weight: 800;
  font-size: 13px;
}

.avatar.small {
  width: 28px;
  height: 28px;
  font-size: 11px;
}

.workspace-name,
.user-name {
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace-plan,
.user-role {
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 14px 26px;
  background: rgba(247, 250, 252, 0.86);
  border-bottom: 1px solid rgba(216, 225, 236, 0.75);
  backdrop-filter: blur(18px);
}

body.theme-dark .topbar {
  background: rgba(7, 19, 31, 0.84);
  border-bottom-color: rgba(37, 64, 88, 0.75);
}

.page-heading {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.mobile-menu {
  display: none;
}

.page-title {
  margin: 0;
  font-size: 25px;
  line-height: 1.2;
  font-weight: 850;
}

.page-kicker {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.page-content {
  padding: 26px;
  min-width: 0;
}

.section {
  margin-bottom: 26px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.section-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.kpis {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card,
.metric,
.table-wrap,
.modal-panel,
.drawer-panel,
.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 1px rgba(16, 32, 51, 0.04);
}

.metric {
  padding: 16px;
  display: grid;
  gap: 12px;
  min-height: 132px;
}

.metric-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-value {
  font-size: 30px;
  line-height: 1;
  font-weight: 880;
}

.metric-trend {
  align-self: start;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--good);
  background: var(--good-soft);
  font-size: 12px;
  font-weight: 800;
}

.metric-trend.warn {
  color: var(--warn);
  background: var(--warn-soft);
}

.metric-trend.bad {
  color: var(--bad);
  background: var(--bad-soft);
}

.metric-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.card {
  padding: 16px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.input,
.select {
  min-height: 40px;
  padding: 9px 11px;
}

.textarea {
  min-height: 96px;
  padding: 11px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 128, 255, 0.12);
}

.search {
  position: relative;
  min-width: 260px;
}

.search .input {
  padding-left: 36px;
}

.search:before {
  content: "Q";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  display: grid;
  place-items: center;
}

.btn,
.icon-btn,
.chip {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 13px;
  color: var(--ink);
  background: var(--surface-raised);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
  font-weight: 750;
  white-space: nowrap;
}

.btn:hover,
.icon-btn:hover,
.chip:hover {
  border-color: var(--primary);
}

.btn:active,
.icon-btn:active,
.chip:active {
  transform: translateY(1px);
}

.btn.primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.btn.primary:hover {
  background: var(--primary-strong);
}

.btn.secondary {
  color: #fff;
  background: var(--secondary);
  border-color: var(--secondary);
}

.btn.danger {
  color: #fff;
  background: var(--bad);
  border-color: var(--bad);
}

.btn.ghost,
.icon-btn {
  border-color: var(--line);
}

.btn.full {
  width: 100%;
}

.icon-btn {
  width: 40px;
  padding: 0;
  flex: 0 0 auto;
}

.icon-btn.mobile-menu {
  display: none;
}

.chip {
  min-height: 34px;
  padding: 7px 11px;
  border-color: var(--line);
  color: var(--muted);
  font-size: 13px;
}

.chip.active {
  color: var(--primary);
  border-color: rgba(0, 128, 255, 0.45);
  background: rgba(0, 128, 255, 0.08);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  background: var(--soft);
  white-space: nowrap;
}

.pill.good {
  color: var(--good);
  background: var(--good-soft);
}

.pill.warn {
  color: var(--warn);
  background: var(--warn-soft);
}

.pill.bad {
  color: var(--bad);
  background: var(--bad-soft);
}

.pill.violet {
  color: var(--violet);
  background: var(--violet-soft);
}

.table-wrap {
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 850;
  background: rgba(0, 128, 255, 0.04);
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tr:hover td {
  background: rgba(0, 128, 255, 0.035);
}

.row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.row-title {
  font-weight: 800;
}

.row-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.pipeline-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  overflow: visible;
  padding-bottom: 8px;
}

.kanban-column {
  min-height: 420px;
  background: rgba(238, 244, 251, 0.68);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

body.theme-dark .kanban-column {
  background: rgba(16, 36, 58, 0.65);
}

.kanban-column.drag-over {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 2px rgba(0, 128, 255, 0.15);
}

.kanban-head {
  position: static;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: inherit;
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
}

.kanban-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 850;
}

.stage-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary);
  flex: 0 0 auto;
}

.kanban-body {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  flex: 1;
}

.deal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(16, 32, 51, 0.08);
}

.deal-card[draggable="true"] {
  cursor: grab;
}

.deal-card.dragging {
  opacity: 0.5;
}

.deal-title {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.deal-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.deal-amount {
  color: var(--ink);
  font-weight: 850;
  font-size: 15px;
}

.probability {
  width: 100%;
  height: 7px;
  border-radius: 99px;
  background: var(--soft);
  overflow: hidden;
}

.probability > span {
  display: block;
  height: 100%;
  width: var(--value);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #1a9988);
}

.mini-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.mini-actions .icon-btn {
  width: 100%;
  min-width: 0;
  height: 34px;
  min-height: 34px;
  font-size: 12px;
}

.chart-bars {
  display: grid;
  gap: 13px;
}

.bar-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 70px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--soft);
}

.bar-fill {
  display: block;
  width: var(--value);
  height: 100%;
  border-radius: inherit;
  background: var(--bar-color, var(--primary));
}

.activity-list {
  display: grid;
  gap: 10px;
}

.activity-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.activity-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--primary);
  font-weight: 900;
}

.activity-title {
  margin: 0;
  font-weight: 800;
}

.activity-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.company-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.company-card {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.company-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.company-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--secondary);
  font-weight: 900;
}

.company-name {
  margin: 0;
  font-size: 16px;
  font-weight: 850;
}

.company-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-box {
  padding: 10px;
  border-radius: 8px;
  background: var(--soft);
}

.stat-value {
  font-weight: 850;
}

.stat-label {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.72fr);
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.switch-row:last-child {
  border-bottom: 0;
}

.toggle {
  position: relative;
  width: 46px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  padding: 0;
}

.toggle:after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 160ms ease;
}

.toggle.on {
  background: var(--primary);
}

.toggle.on:after {
  transform: translateX(20px);
}

.ai-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 900;
  font-size: 17px;
}

.ai-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 60;
  width: min(420px, calc(100vw - 32px));
  max-height: min(660px, calc(100vh - 116px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.ai-title {
  margin: 0;
  font-weight: 850;
}

.ai-messages {
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

.message {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  line-height: 1.45;
  font-size: 14px;
}

.message.user {
  margin-left: auto;
  color: #fff;
  background: var(--primary);
}

.ai-foot {
  padding: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.modal-backdrop,
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 16, 34, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
}

.drawer-backdrop {
  place-items: stretch end;
}

.modal-panel {
  width: min(680px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  box-shadow: var(--shadow);
}

.drawer-panel {
  width: min(480px, 100%);
  height: calc(100vh - 40px);
  overflow: auto;
  box-shadow: var(--shadow);
}

.modal-head,
.drawer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-title,
.drawer-title {
  margin: 0;
  font-size: 19px;
  font-weight: 850;
}

.modal-body,
.drawer-body {
  padding: 18px;
}

.modal-foot,
.drawer-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(145deg, rgba(0, 30, 61, 0.95), rgba(0, 128, 255, 0.72)),
    #001e3d;
}

.login-panel {
  width: min(440px, 100%);
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.empty-state {
  min-height: 170px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 22px;
}

#toast-root {
  position: fixed;
  right: 24px;
  top: 92px;
  z-index: 100;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
}

.toast {
  background: var(--secondary);
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  animation: toast-in 220ms ease both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1180px) {
  .grid.kpis,
  .company-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.two,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -320px;
    z-index: 70;
    width: min(300px, 84vw);
    transform: none;
    transition: none;
  }

  body.nav-open .sidebar {
    left: 0 !important;
  }

  .icon-btn.mobile-menu {
    display: inline-flex;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
    padding: 14px 16px;
  }

  .top-actions {
    justify-content: start;
  }

  .page-content {
    padding: 18px 16px 96px;
  }

  .search {
    min-width: 100%;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }

  .toolbar-right .btn,
  .toolbar-right .chip {
    flex: 1 1 auto;
  }

  .pipeline-board {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .kanban-column {
    min-height: auto;
  }

  .kanban-head {
    position: static;
  }

  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table th,
  .data-table td {
    display: block;
  }

  .data-table thead {
    display: none;
  }

  .data-table tr {
    border-bottom: 1px solid var(--line);
    padding: 10px 0;
  }

  .data-table td {
    border: 0;
    padding: 8px 12px;
  }

  .actions {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .grid.kpis,
  .grid.three,
  .company-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric-value {
    font-size: 26px;
  }

  .page-title {
    font-size: 21px;
  }

  .bar-row {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .bar-row strong {
    grid-column: 1 / -1;
  }

  .activity-item {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .activity-item .actions {
    grid-column: 1 / -1;
  }

  .modal-backdrop,
  .drawer-backdrop {
    padding: 10px;
  }

  .drawer-panel,
  .modal-panel {
    height: auto;
    max-height: calc(100vh - 20px);
  }
}
