:root {
  color-scheme: light;
  --ink: #172024;
  --muted: #64727a;
  --line: #d8e0e4;
  --panel: #ffffff;
  --paper: #f4f7f6;
  --teal: #0f766e;
  --teal-strong: #0b5f59;
  --blue: #2563eb;
  --amber: #b7791f;
  --rose: #b42318;
  --green: #15803d;
  --shadow: 0 18px 45px rgba(23, 32, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body:not(.is-authenticated) .app-shell,
body:not(.is-authenticated) .modal,
body:not(.is-authenticated) .toast {
  display: none;
}

body.is-authenticated .auth-screen {
  display: none;
}

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

button {
  cursor: pointer;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(22, 34, 37, 0.94), rgba(15, 118, 110, 0.72)),
    #162225;
}

.auth-card {
  display: grid;
  gap: 18px;
  width: min(100%, 430px);
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.auth-brand {
  color: var(--ink);
}

.auth-brand span {
  color: var(--muted);
}

.auth-error {
  min-height: 20px;
  margin: -4px 0 0;
  color: var(--rose);
  font-size: 13px;
  font-weight: 800;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  color: #eef7f5;
  background: #162225;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #06211f;
  background: #9be0d9;
  font-weight: 800;
}

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

.brand strong {
  font-size: 16px;
}

.brand span {
  color: #a5b8bc;
  font-size: 13px;
  margin-top: 2px;
}

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

.nav-link {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #dce8ea;
  background: transparent;
  text-align: left;
}

.nav-link:hover,
.nav-link.is-active {
  border-color: rgba(155, 224, 217, 0.32);
  background: rgba(155, 224, 217, 0.1);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 28px;
  border-radius: 6px;
  color: #9be0d9;
  background: rgba(255, 255, 255, 0.08);
  font-size: 11px;
  font-weight: 800;
}

.nav-count {
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #d2fffb;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  text-align: center;
}

.data-tools {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

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

h1 {
  font-size: 32px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 18px;
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

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

.compact-tools {
  justify-content: flex-start;
}

.search-box {
  display: grid;
  gap: 6px;
  width: min(100%, 520px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-box input,
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  padding: 10px 12px;
  outline: none;
}

.search-box input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

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

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 13px;
  font-weight: 800;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #ffffff;
  background: var(--teal);
}

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

.secondary-button {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
}

.ghost-button {
  width: 100%;
  color: #e7f2f0;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  text-align: center;
}

.danger-button {
  color: #ffffff;
  background: var(--rose);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--muted);
  background: #f7faf9;
  border-color: var(--line);
}

.file-button {
  position: relative;
  display: grid;
  place-items: center;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.operation-card,
.client-row,
.active-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(23, 32, 36, 0.06);
}

.operation-card {
  display: grid;
  overflow: hidden;
  text-align: left;
}

.operation-card:hover {
  border-color: rgba(15, 118, 110, 0.38);
  transform: translateY(-1px);
}

.card-media {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.92), rgba(37, 99, 235, 0.78)),
    linear-gradient(45deg, #b7791f, #0f766e);
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-fallback {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  font-size: 24px;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.12);
}

.card-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.card-title-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--teal-strong);
  background: #dff3ef;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.tag.blue {
  color: #1d4ed8;
  background: #e0e7ff;
}

.tag.amber {
  color: #92400e;
  background: #fef3c7;
}

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

.card-meta {
  display: grid;
  gap: 8px;
}

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

.meta-line strong {
  color: var(--ink);
}

.client-list,
.active-list {
  display: grid;
  gap: 12px;
}

.client-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(140px, 0.6fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
}

.client-row-actions,
.active-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.small-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 800;
}

.active-item {
  display: grid;
  gap: 14px;
  padding: 16px;
}

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

.active-clients {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-strip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
  font-weight: 800;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px dashed #b9c7cb;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  padding: 24px;
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.modal {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.detail-modal {
  width: min(1040px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(8, 19, 22, 0.52);
}

.modal-frame {
  display: grid;
  gap: 18px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-head,
.modal-actions,
.split-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-actions {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.modal-actions > div {
  display: flex;
  gap: 8px;
}

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

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

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

.field label,
.choice-group legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.file-hint {
  color: var(--muted);
  font-size: 12px;
}

.doc-list,
.detail-grid {
  display: grid;
  gap: 10px;
}

.doc-list {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.doc-pill,
.detail-cell,
.client-choice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfb;
  padding: 10px;
}

.doc-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.doc-pill a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.doc-remove {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(0, 1fr);
  gap: 18px;
}

.detail-image {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  aspect-ratio: 16 / 11;
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.92), rgba(37, 99, 235, 0.76)),
    #0f766e;
}

.detail-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.detail-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}

.detail-cell strong {
  display: block;
  font-size: 15px;
}

.detail-section-title {
  margin: 18px 0 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
}

.choice-group {
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  margin: 0;
  border: 0;
  padding: 0;
}

.choice-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.client-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #172024;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: static;
    gap: 16px;
  }

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

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

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

  .detail-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar .primary-button {
    width: 100%;
  }
}

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

  h1 {
    font-size: 26px;
  }

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

  .data-tools,
  .modal-actions,
  .split-actions,
  .active-head {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-actions > div,
  .active-actions,
  .client-row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

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