:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #17201d;
  --muted: #68736f;
  --faint: #8c9692;
  --border: #dfe5e2;
  --border-strong: #c8d1cc;
  --sidebar: #111815;
  --sidebar-soft: #1a2420;
  --accent: #0e8f74;
  --accent-dark: #08725c;
  --accent-soft: #e1f4ee;
  --amber: #b7791f;
  --amber-soft: #fff4dd;
  --red: #b13b3b;
  --red-soft: #ffebeb;
  --green: #15845e;
  --green-soft: #e7f7ef;
  --shadow: 0 18px 40px rgba(17, 24, 21, 0.08);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-root {
  min-height: 100vh;
}

.loading-screen,
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.loading-screen {
  gap: 14px;
  align-content: center;
  color: var(--muted);
}

.login-shell {
  width: min(1120px, 100%);
  min-height: 650px;
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(440px, 1.2fr);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.login-shell.single {
  grid-template-columns: minmax(320px, 0.8fr) minmax(360px, 0.9fr);
}

.login-panel {
  padding: 42px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 36px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 760;
  letter-spacing: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.login-copy h1 {
  margin: 0 0 14px;
  max-width: 420px;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 0.98;
  letter-spacing: 0;
}

.login-copy p {
  margin: 0;
  max-width: 420px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.login-card {
  padding: 34px;
  border-left: 1px solid var(--border);
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}

.login-card h2,
.panel-title,
.view-title,
.modal-title {
  margin: 0;
  font-weight: 760;
  letter-spacing: 0;
}

.login-card h2 {
  font-size: 28px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
}

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

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

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

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.textarea {
  min-height: 90px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 143, 116, 0.12);
}

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  color: var(--ink);
  background: #fff;
  font-size: 14px;
  font-weight: 720;
  line-height: 1;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary {
  border-color: var(--border);
  background: var(--surface);
}

.button.ghost {
  color: var(--muted);
  background: transparent;
}

.button.danger {
  background: var(--red-soft);
  color: var(--red);
}

.button.compact {
  min-height: 32px;
  padding: 7px 10px;
  font-size: 12px;
}

.icon {
  width: 17px;
  height: 17px;
  display: inline-block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

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

.demo-account {
  min-height: 54px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  text-align: left;
}

.demo-account strong {
  display: block;
  font-size: 13px;
}

.demo-account span {
  color: var(--muted);
  display: block;
  margin-top: 3px;
  font-size: 12px;
}

.error-text {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  line-height: 1.45;
}

.is-hidden {
  display: none;
}

.crm-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  background: var(--sidebar);
  color: rgba(255, 255, 255, 0.9);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
}

.sidebar .brand-mark {
  background: var(--accent);
}

.nav {
  display: grid;
  gap: 5px;
}

.nav-button {
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: rgba(255, 255, 255, 0.66);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
}

.nav-button:hover,
.nav-button.active {
  background: var(--sidebar-soft);
  color: #fff;
}

.role-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 14px;
}

.role-card p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.58);
  font-size: 12px;
  line-height: 1.45;
}

.role-name {
  font-size: 12px;
  color: #9fe6d2;
  text-transform: uppercase;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: 18px 24px 34px;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  margin: 0 -24px 22px;
  padding: 0 24px 18px;
}

.topbar-title {
  display: grid;
  gap: 4px;
}

.topbar-title h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar-title span {
  color: var(--muted);
  font-size: 13px;
}

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

.user-pill {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  text-align: left;
}

.avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.user-pill strong {
  display: block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.user-pill span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.muted {
  color: var(--muted);
}

.view {
  display: grid;
  gap: 18px;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.view-title {
  font-size: 22px;
}

.view-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

.kpi {
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  display: grid;
  gap: 12px;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi-value {
  font-size: 30px;
  font-weight: 820;
  letter-spacing: 0;
}

.kpi-note {
  color: var(--muted);
  font-size: 13px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(310px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  min-width: 0;
}

.panel-header {
  min-height: 58px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 16px;
}

.panel-body {
  padding: 16px 18px;
}

.notice-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.notice {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  background: var(--surface);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}

.notice strong {
  font-size: 13px;
}

.notice span {
  color: var(--muted);
  font-size: 12px;
}

.notice.warn {
  border-left-color: var(--amber);
  background: var(--amber-soft);
}

.notice.danger {
  border-left-color: var(--red);
  background: var(--red-soft);
}

.notice.active {
  border-left-color: var(--green);
  background: var(--green-soft);
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.stage-column {
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 8px;
  padding: 10px;
}

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

.stage-head strong {
  font-size: 13px;
}

.stage-head span {
  color: var(--muted);
  font-size: 12px;
}

.deal-card {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 11px;
  display: grid;
  gap: 9px;
}

.deal-card.is-draggable {
  cursor: grab;
}

.deal-card.is-draggable:active {
  cursor: grabbing;
}

.deal-card + .deal-card {
  margin-top: 8px;
}

.deal-card h3 {
  margin: 0;
  font-size: 13px;
  line-height: 1.32;
}

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

.progress {
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: #e7ece9;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
}

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

.task-row,
.activity-row,
.person-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.task-row:last-child,
.activity-row:last-child,
.person-row:last-child {
  border-bottom: 0;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--accent);
}

.status-dot.high,
.status-dot.blocked,
.status-dot.at_risk {
  background: var(--red);
}

.status-dot.normal,
.status-dot.proposal,
.status-dot.negotiation,
.status-dot.qualified {
  background: var(--amber);
}

.status-dot.done,
.status-dot.won,
.status-dot.active {
  background: var(--green);
}

.row-title {
  font-size: 13px;
  font-weight: 760;
}

.row-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 820;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.badge.danger {
  background: var(--red-soft);
  color: var(--red);
}

.badge.neutral {
  background: #eef2f0;
  color: var(--muted);
}

.table-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.search {
  position: relative;
  width: min(380px, 100%);
}

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

.search .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 13px;
}

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

.data-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
  text-transform: uppercase;
}

.data-table tr:hover td {
  background: var(--surface-soft);
}

.cell-main {
  display: grid;
  gap: 4px;
}

.cell-main strong {
  font-size: 13px;
}

.cell-main span {
  color: var(--muted);
  font-size: 12px;
}

.inline-actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.compact-select {
  min-height: 32px;
  max-width: 150px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(17, 24, 21, 0.45);
}

.modal {
  width: min(720px, 100%);
  max-height: min(820px, calc(100vh - 44px));
  overflow: auto;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 28px 80px rgba(17, 24, 21, 0.24);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}

.modal-form {
  padding: 20px;
  display: grid;
  gap: 15px;
}

.empty {
  min-height: 130px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 22px;
}

.compact-empty {
  min-height: 96px;
  padding: 14px;
}

.filter-bar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
}

.field.mini {
  min-width: 170px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
  font-weight: 820;
}

.link-button:hover {
  color: var(--accent-dark);
}

.tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 3px 7px;
  margin: 2px 4px 2px 0;
  border-radius: 999px;
  background: #eef2f0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 0.9fr);
  gap: 16px;
  align-items: stretch;
  padding: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
}

.detail-hero h2 {
  margin: 12px 0 8px;
  font-size: 28px;
  line-height: 1.05;
}

.detail-hero p {
  margin: 0 0 12px;
  color: var(--muted);
}

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

.detail-metrics .kpi {
  min-height: 102px;
  padding: 14px;
}

.detail-metrics .kpi-value {
  font-size: 20px;
}

.note-block {
  padding: 13px 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  line-height: 1.5;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-item:last-child {
  border-bottom: 0;
}

.mini-form {
  display: grid;
  gap: 12px;
  padding: 0 0 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.mini-form:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.textarea.tall {
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.calendar-list,
.chart-list,
.audit-list,
.notification-list,
.workflow-list,
.product-bom {
  display: grid;
  gap: 12px;
}

.calendar-item {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.calendar-item:last-child {
  border-bottom: 0;
}

.calendar-date {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 820;
  text-transform: uppercase;
}

.chart-row {
  display: grid;
  gap: 8px;
}

.search.wide {
  width: min(760px, 100%);
}

.search-result {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  text-align: left;
}

.search-result:last-child {
  border-bottom: 0;
}

.search-result strong,
.search-result span {
  display: block;
}

.search-result span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.role-permission-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 13px;
}

.role-permission-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.copy-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px dashed var(--border-strong);
  background: var(--surface-soft);
}

.copy-box code {
  display: block;
  overflow-x: auto;
  color: var(--accent-dark);
  font-size: 12px;
  white-space: nowrap;
}

.bom-card,
.workflow-rule {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 13px;
}

.bom-card {
  display: grid;
  gap: 10px;
}

.bom-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.workflow-rule {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) auto 120px minmax(260px, 1.4fr) auto;
  gap: 12px;
  align-items: center;
}

.workflow-rule .field,
.workflow-rule .field-grid {
  margin: 0;
}

.workflow-rule .workflow-template .textarea {
  min-height: 64px;
}

.modal.narrow {
  width: min(620px, 100%);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  min-width: min(360px, calc(100vw - 36px));
  padding: 13px 15px;
  border-radius: 8px;
  background: var(--sidebar);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.mobile-top {
  display: none;
}

@media (max-width: 1120px) {
  .crm-shell {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .sidebar {
    padding: 18px 12px;
    align-items: center;
  }

  .sidebar .brand-row span,
  .nav-button span,
  .role-card {
    display: none;
  }

  .nav-button {
    justify-content: center;
    padding: 12px;
  }
}

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

  .login-card {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .dashboard-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

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

  .field-grid.three,
  .workflow-rule {
    grid-template-columns: 1fr;
  }

  .detail-hero,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .detail-metrics {
    grid-template-columns: 1fr;
  }

  .permission-grid {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: static;
    min-height: auto;
    flex-direction: row;
    overflow-x: auto;
    justify-content: flex-start;
    align-items: center;
    padding: 10px;
  }

  .sidebar .brand-row {
    display: none;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
  }

  .workspace {
    padding: 14px 14px 28px;
  }

  .topbar {
    margin: 0 -14px 16px;
    padding: 0 14px 14px;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .button {
    min-height: 38px;
  }

  .login-panel,
  .login-card {
    padding: 26px;
  }

  .demo-grid {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    align-items: stretch;
  }

  .field.mini,
  .filter-bar .button,
  .filter-bar a.button {
    width: 100%;
  }

  .calendar-item {
    grid-template-columns: 1fr;
  }
}
