:root {
  --navy: #17233c;
  --navy-2: #223252;
  --blue: #315ea8;
  --blue-soft: #edf3fc;
  --green: #27805f;
  --green-soft: #eaf7f1;
  --amber: #b36a16;
  --amber-soft: #fff5e7;
  --red: #b64242;
  --ink: #1d2533;
  --muted: #687386;
  --line: #e2e7ef;
  --surface: #ffffff;
  --canvas: #f4f6f9;
  --shadow: 0 10px 30px rgba(28, 45, 78, 0.07);
  --radius: 14px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: "PT Sans", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

.shell { min-height: 100vh; }

.rail {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: 250px;
  display: flex;
  flex-direction: column;
  padding: 26px 18px 20px;
  color: #fff;
  background: var(--navy);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 12px;
  padding: 5px;
  background: #fff;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-copy h1 { margin: 0; font-size: 18px; line-height: 1.1; }
.brand-kicker { margin: 4px 0 0; color: #9eabc2; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }

.sidebar-nav { display: grid; gap: 5px; }
.nav-label { margin: 18px 12px 7px; color: #7f8ea9; font-size: 11px; letter-spacing: .11em; text-transform: uppercase; }
.nav-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  color: #bbc5d6;
  background: transparent;
  text-align: left;
  transition: .15s ease;
}
.nav-button:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-button.is-active { color: #fff; background: var(--navy-2); box-shadow: inset 3px 0 #f1c453; }
.nav-icon { width: 19px; height: 19px; display: grid; place-items: center; font-size: 16px; }
.nav-count { margin-left: auto; min-width: 24px; padding: 1px 6px; border-radius: 20px; color: #dbe3ef; background: rgba(255,255,255,.1); font-size: 12px; text-align: center; }

.rail-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px; color: #9eabc2; font-size: 13px; }
.rail-footer p { margin: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #62d6a6; box-shadow: 0 0 0 4px rgba(98,214,166,.12); }

.main { min-height: 100vh; margin-left: 250px; }
.auth-mode .rail { display: none; }
.auth-mode .main { margin-left: 0; }
.workspace { max-width: 1460px; margin: 0 auto; padding: 0 34px 48px; }

.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}
.page-heading { margin: 0; font-size: 24px; line-height: 1.2; }
.page-caption { margin: 4px 0 0; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { text-align: right; }
.user-chip strong, .user-chip span { display: block; }
.user-chip span { color: var(--muted); font-size: 12px; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--blue); font-weight: 700; }

.page { padding-top: 28px; }
.page-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-intro h3 { margin: 0; font-size: 22px; }
.page-intro p { margin: 5px 0 0; color: var(--muted); }

.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric, .card, .table-card, .form-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metric { position: relative; overflow: hidden; padding: 22px; }
.metric::after { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--blue); }
.metric-label { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 7px; color: var(--navy); font-size: 32px; line-height: 1; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .75fr); gap: 20px; }
.card { padding: 22px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.card-head h3, .form-card h3, .table-card h3 { margin: 0; font-size: 18px; }
.card-head p, .form-card > p, .table-card > p { margin: 5px 0 0; color: var(--muted); }
.quick-card { color: #fff; background: linear-gradient(135deg, var(--navy), #29436f); border-color: transparent; }
.quick-card h3 { font-size: 22px; }
.quick-card p { max-width: 530px; color: #cbd4e4; }
.quick-card .button { color: var(--navy); background: #fff; }

.list-stack { display: grid; gap: 10px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item-main strong, .list-item-main span { display: block; }
.list-item-main span { margin-top: 2px; color: var(--muted); font-size: 13px; }

.status-pill, .role-badge, .mini-tag { display: inline-flex; align-items: center; width: fit-content; border-radius: 999px; white-space: nowrap; }
.status-pill { padding: 4px 9px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 700; }
.status-pill.weather { color: var(--amber); background: var(--amber-soft); }
.status-pill.disabled { color: var(--muted); background: #eef1f5; }
.role-badge { padding: 5px 10px; color: var(--blue); background: var(--blue-soft); font-size: 12px; font-weight: 700; }
.mini-tag { padding: 3px 8px; color: #586477; background: #f0f3f7; font-size: 12px; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr); gap: 20px; }
.form-card, .table-card { padding: 22px; }
.form-grid { display: grid; gap: 16px; margin-top: 20px; }
.form-grid.dual { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.triple { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; min-width: 0; }
.field label { color: #3c4657; font-size: 13px; font-weight: 700; }
.field-span { grid-column: 1 / -1; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #d6dce5;
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fff;
  transition: .15s ease;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(49,94,168,.11); }
input::placeholder, textarea::placeholder { color: #a1a9b6; }

.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.button, .secondary-button, .ghost-button, .copy-button, .danger-button {
  min-height: 40px;
  padding: 9px 15px;
  border-radius: 9px;
  font-weight: 700;
  transition: .15s ease;
}
.button { border: 1px solid var(--blue); color: #fff; background: var(--blue); }
.button:hover { background: #274f90; }
.secondary-button, .copy-button { border: 1px solid #d8dee8; color: #344054; background: #fff; }
.secondary-button:hover, .copy-button:hover { border-color: #b9c3d1; background: #f8fafc; }
.ghost-button { border: 0; color: var(--blue); background: transparent; }
.danger-button { border: 1px solid #efd1d1; color: var(--red); background: #fff7f7; }
.button:disabled { cursor: wait; opacity: .6; }

.stepper { display: flex; align-items: center; gap: 8px; margin: 18px 0 22px; }
.step { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.step-number { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; color: var(--blue); background: var(--blue-soft); font-weight: 700; }
.step-line { width: 30px; height: 1px; background: var(--line); }
.context-list { display: grid; gap: 14px; margin-top: 18px; }
.context-row { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.context-row:last-child { border-bottom: 0; }
.context-row span, .context-row strong { display: block; }
.context-row span { color: var(--muted); font-size: 12px; }
.context-row strong { margin-top: 3px; }
.weather-link { display: inline-flex; margin-top: 14px; color: var(--blue); font-weight: 700; text-decoration: none; }

.result-card { margin-top: 18px; padding: 20px; border: 1px solid #bfe4d4; border-radius: 12px; background: var(--green-soft); }
.result-card h4 { margin: 0 0 6px; color: #195e46; font-size: 18px; }
.result-card p { margin: 0 0 14px; color: #42715f; }
.copy-fields { display: grid; gap: 10px; margin-top: 14px; }
.copy-field { padding: 12px; border: 1px solid #d5e7df; border-radius: 9px; background: #fff; }
.copy-field span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.copy-field p { margin: 0; color: var(--ink); white-space: pre-wrap; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }
.filters input { max-width: 360px; }
.filters select { max-width: 210px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: #f8fafc; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:hover { background: #fafbfd; }
td { font-size: 14px; }
.table-actions { display: flex; gap: 6px; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid #d8dee8; border-radius: 8px; color: var(--blue); background: #fff; text-decoration: none; }
.subject-cell { min-width: 210px; max-width: 320px; }
.comment-cell { color: var(--muted); }
.empty-state { padding: 34px 18px; color: var(--muted); text-align: center; }

.object-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.object-card { padding: 20px; }
.object-card h3 { margin: 0; }
.object-meta { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin: 18px 0; }
.object-meta span, .object-meta strong { display: block; }
.object-meta span { color: var(--muted); font-size: 12px; }
.contract-list { display: grid; gap: 8px; }
.contract-item { display: flex; justify-content: space-between; gap: 12px; padding: 11px 12px; border-radius: 9px; background: #f7f9fc; }
.object-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.object-actions > span { color: var(--muted); font-size: 13px; }
.object-editor { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.object-editor summary { cursor: pointer; color: var(--blue); font-weight: 700; }
.contract-form-heading { margin-top: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.contract-form-heading strong, .contract-form-heading span { display: block; }
.contract-form-heading span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.editor-toolbar { position: sticky; top: 12px; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border: 1px solid #cbd8eb; border-radius: 11px; background: #f4f8fe; box-shadow: 0 7px 18px rgba(28,45,78,.1); }
.editor-toolbar strong, .editor-toolbar span { display: block; }
.editor-toolbar span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; padding: 13px 18px; border-radius: 10px; color: #fff; background: var(--green); box-shadow: 0 14px 35px rgba(22,70,53,.25); opacity: 0; transform: translateY(12px); transition: .2s ease; font-weight: 700; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; padding: 4px; width: fit-content; border-radius: 10px; background: #e9edf3; }
.tab-button { padding: 8px 14px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-weight: 700; }
.tab-button.is-active { color: var(--ink); background: #fff; box-shadow: 0 2px 8px rgba(20,33,56,.08); }

.user-list { display: grid; gap: 10px; }
.users-layout { grid-template-columns: minmax(360px, .8fr) minmax(0, 1.4fr); }
.users-layout > * { min-width: 0; }
.user-row { display: grid; grid-template-columns: minmax(170px,1fr) minmax(150px,180px) minmax(120px,140px) auto; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 11px; }
.user-row .button-row { flex-wrap: nowrap; }
.user-name strong, .user-name span { display: block; }
.user-name span { color: var(--muted); font-size: 12px; }
.invite-link { padding: 10px 12px; overflow-wrap: anywhere; border: 1px dashed #c5cfdd; border-radius: 9px; color: var(--blue); background: #f7faff; }

.audit-list { margin: 18px 0 0; padding: 0; list-style: none; }
.audit-item { position: relative; padding: 0 0 18px 24px; border-left: 1px solid var(--line); }
.audit-item::before { content: ""; position: absolute; left: -5px; top: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--blue); }
.audit-item strong, .audit-item span { display: block; }
.audit-item span { margin-top: 3px; color: var(--muted); font-size: 12px; }

.flash { min-height: 20px; color: var(--red); font-size: 13px; }
.flash.success { color: var(--green); }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: 11px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }

.auth-layout { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 70% 10%, #e9f0fb, transparent 38%); }
.auth-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: 0 24px 65px rgba(26,40,66,.13); }
.auth-logo { width: 82px; height: 76px; display: grid; place-items: center; margin-bottom: 24px; padding: 8px; border-radius: 16px; background: var(--navy); }
.auth-logo img { width: 100%; height: 100%; object-fit: contain; }
.auth-card h2 { margin: 0; font-size: 28px; }
.auth-card > p { margin: 8px 0 0; color: var(--muted); }
.register-layout { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.register-card { width: min(650px,100%); padding: 30px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }

.mobile-menu { display: none; }

@media (max-width: 1500px) {
  .users-layout { grid-template-columns: 1fr; }
}

@media (max-width: 1050px) {
  .overview-grid, .content-grid { grid-template-columns: 1fr; }
  .object-grid { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: minmax(180px,1fr) 150px 120px; }
  .user-row .button-row { grid-column: 1 / -1; flex-wrap: wrap; }
}

@media (max-width: 760px) {
  .rail { position: static; width: 100%; min-height: auto; padding: 14px 16px; }
  .brand { padding: 0; }
  .brand-mark { width: 36px; height: 36px; }
  .sidebar-nav { grid-template-columns: repeat(4, 1fr); margin-top: 12px; }
  .nav-label, .rail-footer, .nav-count { display: none; }
  .nav-button { justify-content: center; padding: 9px 5px; font-size: 12px; }
  .nav-icon { display: none; }
  .main { margin-left: 0; }
  .workspace { padding: 0 16px 36px; }
  .topbar { min-height: 70px; }
  .page-caption, .user-chip { display: none; }
  .metrics { grid-template-columns: 1fr; }
  .form-grid.dual, .form-grid.triple, .object-meta { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr; }
  .editor-toolbar { position: static; align-items: stretch; flex-direction: column; }
  .editor-toolbar .button { width: 100%; }
  .object-actions { align-items: stretch; flex-direction: column; }
  .topbar-actions .secondary-button { padding-inline: 10px; }
  .page-intro { align-items: flex-start; flex-direction: column; }
}
