:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #eef2f7;
  --text: #152033;
  --muted: #647084;
  --line: #dfe5ee;
  --brand: #1167d8;
  --brand-strong: #0a4eaa;
  --green: #16865a;
  --amber: #b86800;
  --coral: #ca4f3d;
  --shadow: 0 18px 45px rgba(28, 43, 70, 0.08);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #10141b;
  --surface: #171d27;
  --surface-soft: #212a38;
  --text: #eef3fb;
  --muted: #a7b2c4;
  --line: #2d394b;
  --brand: #62a4ff;
  --brand-strong: #8fc0ff;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-width: 320px;
}

body.locked .app-shell {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: none;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(10, 27, 48, 0.9), rgba(17, 103, 216, 0.72)),
    url("https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&fit=crop&w=1600&q=80") center/cover;
}

body.locked .login-screen {
  display: grid;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 18px;
}

.login-brand {
  color: var(--text);
}

.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.login-tabs button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.login-tabs button.active {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}

.login-form {
  display: none;
  gap: 12px;
}

.login-form.active {
  display: grid;
}

.login-error {
  min-height: 22px;
  color: var(--coral);
  font-weight: 800;
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(24px);
  opacity: 0;
  z-index: 40;
  background: #0f1724;
  color: #ffffff;
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 24px));
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0f1724;
  color: #eef3fb;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #ffffff;
  color: #0f1724;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #aab6c8;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  color: #dbe5f2;
  background: transparent;
  padding: 12px;
  border-radius: 8px;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #1d2a3f;
  color: #ffffff;
}

.sidebar-card {
  margin-top: auto;
  border: 1px solid #2e3b50;
  border-radius: 8px;
  padding: 16px;
  background: #172236;
}

.sidebar-card p {
  color: #b7c2d4;
  line-height: 1.5;
  margin: 12px 0 0;
}

.pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.main {
  padding: 28px;
  display: grid;
  gap: 22px;
  align-content: start;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  margin-bottom: 0;
}

h2 {
  font-size: 20px;
  margin-bottom: 0;
}

.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 800;
  font-size: 12px;
  margin-bottom: 6px;
}

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

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  min-height: 44px;
  min-width: min(340px, 100%);
}

.search input {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  width: 100%;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  color: var(--text);
}

.primary-button {
  background: var(--brand);
  color: #ffffff;
  padding: 0 16px;
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line);
  padding: 0 14px;
}

.icon-button {
  width: 42px;
  background: var(--surface);
  border-color: var(--line);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 22px;
}

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

.metric,
.panel,
.table-wrap,
.portal-preview,
.portal-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
}

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 4px;
}

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

.metric-icon {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
}

.metric-icon.blue { background: #dbeafe; color: #155db8; }
.metric-icon.green { background: #dcfce7; color: var(--green); }
.metric-icon.amber { background: #fef3c7; color: var(--amber); }
.metric-icon.coral { background: #ffe4df; color: var(--coral); }

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

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

.panel {
  padding: 18px;
}

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

.pipeline {
  display: grid;
  gap: 12px;
}

.pipeline-row,
.task-item,
.activity-item,
.template-item,
.missing-item,
.payment-item,
.country-item,
.portal-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.pipeline-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.6fr) 1fr 48px;
  align-items: center;
  gap: 12px;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

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

.task-list,
.activity-list,
.template-list,
.missing-docs,
.payment-list,
.country-list,
.portal-list {
  display: grid;
  gap: 10px;
}

.task-item,
.activity-item,
.payment-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.task-item strong,
.activity-item strong,
.payment-item strong {
  display: block;
  margin-bottom: 4px;
}

.task-item small,
.activity-item small,
.payment-item small,
td small {
  color: var(--muted);
}

.toolbar {
  justify-content: space-between;
}

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

.segmented button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
  font-weight: 800;
}

.segmented button.active {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}

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

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

th,
td {
  text-align: left;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: var(--surface-soft);
}

.document-layout,
.template-editor-layout,
.portal-shell,
.calendar-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
}

.template-editor-layout {
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
}

.template-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
}

.template-button.active {
  border-color: var(--brand);
  background: var(--surface-soft);
}

.template-form {
  align-content: start;
  display: grid;
  gap: 14px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.list-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.upload-list,
.note-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.upload-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.upload-preview {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.upload-preview img,
.upload-preview iframe {
  width: 100%;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.upload-preview img {
  object-fit: contain;
}

.reject-box {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.customer-only-upload {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.template-item header,
.missing-item header,
.country-item header,
.portal-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

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

.doc-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
}

.doc-action:hover {
  border-color: var(--brand);
  color: var(--brand);
}

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

.calendar-day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 220px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.calendar-day h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.appointment {
  border-left: 4px solid var(--brand);
  padding: 10px 0 10px 10px;
  margin-bottom: 10px;
}

.portal-shell {
  grid-template-columns: 320px 1fr;
}

.portal-list {
  padding: 12px;
  align-content: start;
}

.portal-case-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
}

.portal-case-button.active {
  border-color: var(--brand);
  background: var(--surface-soft);
}

.portal-preview {
  padding: 24px;
}

.portal-hero {
  border-radius: 8px;
  padding: 22px;
  color: #ffffff;
  background:
    linear-gradient(90deg, rgba(11, 39, 73, 0.9), rgba(17, 103, 216, 0.72)),
    url("https://images.unsplash.com/photo-1488646953014-85cb44e25828?auto=format&fit=crop&w=1400&q=80") center/cover;
  min-height: 180px;
  display: grid;
  align-content: end;
}

.portal-hero h2 {
  font-size: clamp(26px, 4vw, 40px);
  margin-bottom: 8px;
}

.portal-stepper {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0;
}

.step {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.step.complete {
  background: #e9f8ef;
  color: #10633f;
  border-color: #b7e3ca;
}

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

.case-dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(760px, calc(100vw - 24px));
  background: var(--surface);
  color: var(--text);
}

.case-dialog::backdrop {
  background: rgba(12, 20, 32, 0.56);
}

.case-form {
  padding: 20px;
  display: grid;
  gap: 16px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.dialog-actions {
  justify-content: flex-end;
}

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

.settings-layout {
  display: grid;
  gap: 18px;
}

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

.brand-mark.has-logo {
  background: #ffffff;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 42px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .metric-grid,
  .two-columns,
  .document-layout,
  .template-editor-layout,
  .portal-shell,
  .calendar-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .main,
  .sidebar {
    padding: 18px;
  }

  .sidebar {
    gap: 16px;
    padding-bottom: 12px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 8px;
    scrollbar-width: thin;
  }

  .nav-item {
    min-width: 118px;
    min-height: 74px;
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    gap: 8px;
    padding: 10px;
    font-size: 13px;
  }

  .nav-item svg {
    width: 22px;
    height: 22px;
  }

  .sidebar-card {
    display: none;
  }

  .topbar,
  .task-item,
  .activity-item,
  .payment-item {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .search,
  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .metric-grid,
  .two-columns,
  .document-layout,
  .portal-shell,
  .calendar-grid,
  .form-grid,
  .portal-details,
  .portal-stepper,
  .inline-form {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .pipeline-row {
    grid-template-columns: 1fr;
  }
}
