:root {
  --ink: #10151d;
  --ink-2: #273241;
  --muted: #667085;
  --line: #e5e7eb;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --accent: #087a6f;
  --accent-2: #e8f5f2;
  --green: #067647;
  --green-2: #ecfdf3;
  --gold: #8a6100;
  --gold-2: #fffaeb;
  --blue: #245b96;
  --blue-2: #eff6ff;
  --red: #b42318;
  --red-2: #fff4f2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 18px 42px rgba(16, 24, 40, .06);
  --shadow-soft: 0 1px 2px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.42;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  background: var(--ink);
}

.auth-panel {
  background: var(--panel);
  padding: 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-context {
  color: #eef5f1;
  padding: 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(120deg, rgba(15,123,99,.55), transparent 38%),
    radial-gradient(circle at 75% 25%, rgba(183,121,31,.25), transparent 34%),
    #101417;
}

.brand-mark {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: linear-gradient(180deg, #0f8f7f, #08766d);
  color: white;
  font-weight: 800;
  letter-spacing: .02em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 34px;
  min-width: 0;
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .04em;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: .12em;
  font-size: 12px;
}

h1, h2, h3 {
  letter-spacing: 0;
  margin: 0;
}

.auth-context h1 {
  font-size: 44px;
  line-height: 1.05;
  max-width: 720px;
}

.auth-context p {
  color: #bccac6;
  max-width: 660px;
  font-size: 18px;
  line-height: 1.6;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field.full { grid-column: 1 / -1; }

label {
  font-size: 12px;
  font-weight: 760;
  color: #3f4a55;
  text-transform: uppercase;
  letter-spacing: .06em;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  padding: 11px 12px;
  min-height: 42px;
  outline: none;
}

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

input:focus, select:focus, textarea:focus {
  border-color: rgba(10, 124, 114, .62);
  box-shadow: 0 0 0 3px rgba(10, 124, 114, .12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 9px 13px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 760;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
}

.btn:hover {
  filter: none;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(16, 24, 40, .10);
}
.btn.primary {
  background: #087a6f;
  border-color: #087a6f;
}
.btn.secondary,
.btn.blue {
  background: #fff;
  color: #245b96;
  border-color: #c9d8eb;
}
.btn.gold {
  background: #fff;
  color: #8a5a00;
  border-color: #edd48f;
}
.btn.danger {
  background: #fff;
  color: var(--red);
  border-color: #f4c7c0;
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
  box-shadow: none;
}
.btn.light {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}
.btn.small {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 13px;
}

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

.sidebar {
  background: #10151c;
  color: #eaf0ed;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand-row {
  margin-bottom: 26px;
  padding-left: 6px;
}

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

.nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #c4ccd4;
  font-weight: 720;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav a.active,
.nav a:hover {
  color: #fff;
  background: rgba(255,255,255,.10);
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 74px;
  padding: 18px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 22px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  max-width: min(520px, 48vw);
}

.user-chip > div {
  min-width: 0;
}

.user-chip strong,
.user-chip .sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip .sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-2);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
}

.content {
  padding: 28px 30px 44px;
  max-width: 1680px;
  margin: 0 auto;
  width: 100%;
}

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

.grid > * { min-width: 0; }

.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }

.panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel { padding: 20px; }
.card { padding: 18px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.panel-title {
  display: grid;
  gap: 5px;
  min-width: min(100%, 260px);
  flex: 1 1 260px;
}

.panel-title h2 { font-size: 18px; }
.panel-title p, .muted { color: var(--muted); margin: 0; line-height: 1.45; }

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

.metric strong {
  font-size: 28px;
  line-height: 1;
}

.metric span { color: var(--muted); font-weight: 700; }

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 760;
  line-height: 1.15;
  max-width: 100%;
  text-align: center;
  white-space: normal;
  border: 1px solid transparent;
}

.status.green { color: #067647; background: var(--green-2); border-color: #b7e4c7; }
.status.gold { color: #8a6100; background: var(--gold-2); border-color: #f2d98b; }
.status.blue { color: #245b96; background: var(--blue-2); border-color: #c7ddf3; }
.status.red { color: var(--red); background: var(--red-2); border-color: #f4c7c0; }
.status.gray { color: #53606c; background: #f2f4f7; border-color: #e4e7ec; }

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 0;
}

.table-wrap table {
  min-width: 900px;
}

th, td {
  text-align: left;
  padding: 15px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  overflow-wrap: normal;
  word-break: normal;
}

th {
  font-size: 12px;
  color: #667085;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

td .sub {
  color: var(--muted);
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

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

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

.actions input,
.actions select {
  width: auto;
  max-width: 240px;
}

.table-wrap .actions {
  flex-wrap: nowrap;
  align-items: center;
  white-space: nowrap;
}

.table-wrap .actions form {
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.compact-actions .btn {
  min-height: 34px;
  padding-inline: 8px;
}

.compact-actions,
.compact-actions form {
  gap: 5px;
}

.companies-table th,
.companies-table td {
  padding-inline: 8px;
}

.upload-actions {
  gap: 6px;
}

.upload-actions input[name="proof_note"] {
  width: 132px;
}

.upload-actions input[type="file"] {
  width: 138px;
  min-height: 34px;
  padding: 6px;
  font-size: 12px;
}

.companies-table th:nth-child(1),
.companies-table td:nth-child(1) { min-width: 190px; }
.companies-table th:nth-child(2),
.companies-table td:nth-child(2) { min-width: 84px; }
.companies-table th:nth-child(3),
.companies-table td:nth-child(3) { min-width: 74px; }
.companies-table th:nth-child(4),
.companies-table td:nth-child(4) { min-width: 104px; }
.companies-table th:nth-child(5),
.companies-table td:nth-child(5) { min-width: 112px; }
.companies-table th:nth-child(6),
.companies-table td:nth-child(6) { min-width: 78px; }
.companies-table th:nth-child(7),
.companies-table td:nth-child(7) {
  min-width: 220px;
  width: 220px;
}

.companies-table .compact-actions {
  min-width: 208px;
}

.companies-table .compact-actions .btn {
  font-size: 12px;
  padding-inline: 7px;
}

.companies-table td:nth-child(3),
.companies-table td:nth-child(6) {
  line-height: 1.25;
}

.flash {
  margin: 0 0 18px;
  padding: 13px 15px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}

.flash.ok { border-color: #b9e3d7; color: #075c49; background: #eefaf6; }
.flash.error { border-color: #f1b5af; color: var(--red); background: #fff2f0; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.tabs a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.tabs a.active {
  color: #fff;
  border-color: var(--green);
  background: var(--green);
}

.deal-flow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  max-width: 100%;
}

.auth-context .deal-flow {
  grid-template-columns: repeat(7, minmax(105px, 1fr));
}

.flow-step {
  background: linear-gradient(180deg, #f7fffc, #edf8f5);
  border: 1px solid #cfeee6;
  padding: 12px;
  border-radius: 10px;
  min-height: 76px;
  min-width: 0;
}

.flow-step.active {
  background: linear-gradient(180deg, #f7fffc, #e4f6f1);
  border-color: #b8e5db;
}

.flow-step span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
}

.flow-step strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  text-wrap: balance;
}

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

.timeline-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.timeline-row time {
  color: var(--muted);
  font-size: 13px;
}

.notice {
  background: var(--gold-2);
  border: 1px solid #f0d39b;
  color: #704307;
  padding: 13px 15px;
  border-radius: 8px;
}

.danger-text { color: var(--red); font-weight: 900; }
.success-text { color: var(--green); font-weight: 900; }

.mobile-nav-toggle { display: none; }

.file-control {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.file-control:hover {
  border-color: #c8d0da;
}

.file-control input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}

.file-control span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-actions .file-control {
  width: 152px;
  min-height: 34px;
  padding: 7px 9px;
  font-size: 12px;
}

@media (max-width: 1600px) {
  .grid.cols-2:has(.table-wrap) {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1400px) {
  .app-shell {
    grid-template-columns: 228px minmax(0, 1fr);
  }
  .sidebar {
    padding: 22px 14px;
  }
  .content {
    padding: 24px 24px 40px;
  }
  .topbar {
    padding: 16px 24px;
  }
}

@media (max-width: 980px) {
  .auth-shell, .app-shell { grid-template-columns: 1fr; }
  .auth-context { display: none; }
  .auth-panel { padding: 34px 24px; min-height: 100vh; }
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 30;
    padding: 14px 16px 12px;
  }
  .sidebar .brand-row {
    margin-bottom: 12px;
    padding-left: 0;
  }
  .sidebar .brand-mark {
    width: 36px;
    height: 36px;
  }
  .sidebar .brand-name {
    font-size: 16px;
  }
  .nav {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    flex: 0 0 auto;
    padding: 9px 11px;
    white-space: nowrap;
  }
  .topbar {
    position: relative;
    padding: 16px 20px;
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .user-chip {
    max-width: none;
    width: 100%;
    justify-content: flex-start;
  }
  .content { padding: 20px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .deal-flow { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .table-wrap {
    overflow: visible;
  }
  .table-wrap table {
    min-width: 0;
    display: block;
  }
  .table-wrap thead {
    display: none;
  }
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
  }
  .table-wrap tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fff;
  }
  .table-wrap td {
    border-bottom: 0;
    padding: 7px 0;
    display: grid;
    grid-template-columns: minmax(96px, 36%) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
  }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .06em;
    text-transform: uppercase;
  }
  .table-wrap td[data-label=""],
  .table-wrap td:not([data-label]) {
    display: block;
  }
  .table-wrap td[data-label=""]::before,
  .table-wrap td:not([data-label])::before {
    content: none;
  }
  .table-wrap td > .status {
    justify-self: start;
  }
  .actions,
  .actions form {
    align-items: stretch;
    width: 100%;
  }
  .table-wrap .actions {
    flex-wrap: wrap;
    white-space: normal;
  }
  .table-wrap .actions form {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }
  .table-wrap td.actions {
    display: block;
  }
  .table-wrap td.actions::before {
    display: block;
    margin-bottom: 8px;
  }
  .actions .btn,
  .actions form,
  .actions input,
  .actions select {
    width: 100%;
    max-width: none;
  }
  .upload-actions .file-control {
    width: 100%;
  }
}

@media (max-width: 720px) {
  body { font-size: 14px; }
  .auth-panel { padding: 26px 18px; }
  .topbar h1 { font-size: 20px; }
  .content { padding: 16px; }
  .panel, .card { padding: 16px; }
  .panel-head {
    display: grid;
    grid-template-columns: 1fr;
  }
  .panel-head > input {
    max-width: none !important;
    width: 100%;
  }
  .metric strong { font-size: 24px; }
  .timeline-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }
}
