:root {
  color-scheme: light;
  --ink: #17352f;
  --ink-soft: #60736e;
  --green-950: #092e27;
  --green-900: #0d3b32;
  --green-800: #155044;
  --green-700: #1d6857;
  --green-100: #dce9e3;
  --green-50: #eef5f1;
  --sand: #f3f5ef;
  --paper: #fffefa;
  --gold: #e6b85c;
  --gold-soft: #f7e9bd;
  --warning: #c8782b;
  --danger: #b84c46;
  --line: #dce3dc;
  --shadow: 0 16px 42px rgba(24, 54, 46, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--sand); scroll-behavior: smooth; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% -10%, rgba(230, 184, 92, 0.16), transparent 30rem),
    var(--sand);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.auth-pending > .topbar, .auth-pending > .app-shell, .auth-pending > .mobile-nav { display: none; }
.auth-screen { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: radial-gradient(circle at 70% 10%, rgba(230,184,92,.22), transparent 30rem), linear-gradient(135deg, var(--green-950), var(--green-800)); }
.auth-card { width: min(430px, 100%); padding: 34px; border-radius: 24px; background: var(--paper); box-shadow: 0 28px 70px rgba(0,0,0,.28); }
.auth-logo { width: 54px; height: 54px; margin-bottom: 22px; display: grid; place-items: center; border-radius: 16px; color: var(--green-950); background: var(--gold); font-size: 29px; font-weight: 900; }
.auth-card h1 { margin: 5px 0 8px; font: 600 36px Georgia, serif; }
.auth-card > p:not(.eyebrow):not(.auth-error) { margin: 0 0 24px; color: var(--ink-soft); line-height: 1.55; }
.auth-card h2 { margin: 0 0 5px; font-size: 18px; }
.auth-error { min-height: 20px; margin: 14px 0 0; color: var(--danger); font-size: 12px; font-weight: 750; }

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 72px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background: linear-gradient(105deg, var(--green-950), var(--green-900));
  box-shadow: 0 6px 20px rgba(9, 46, 39, 0.16);
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 13px;
  color: var(--green-950); background: var(--gold); font-size: 24px; font-weight: 900;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; letter-spacing: 0.01em; }
.brand small { margin-top: 2px; color: rgba(255,255,255,.62); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.system-state { display: flex; align-items: center; gap: 8px; color: rgba(255,255,255,.78); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.user-name { color: rgba(255,255,255,.82); font-size: 12px; }
.logout-button { padding: 7px 10px; border: 1px solid rgba(255,255,255,.25); border-radius: 8px; color: white; background: transparent; font-size: 11px; font-weight: 750; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #e1b04d; box-shadow: 0 0 0 4px rgba(225,176,77,.14); }
.status-dot.online { background: #6fd1a4; box-shadow: 0 0 0 4px rgba(111,209,164,.14); }
.status-dot.offline { background: #e1746e; box-shadow: 0 0 0 4px rgba(225,116,110,.14); }

.app-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar {
  position: sticky; top: 72px; height: calc(100vh - 72px); padding: 28px 18px 22px;
  display: flex; flex-direction: column; justify-content: space-between;
  overflow-y: auto; border-right: 1px solid var(--line); background: rgba(255,254,250,.78); backdrop-filter: blur(12px);
}
.navigation { display: grid; gap: 7px; }
.nav-item {
  width: 100%; padding: 13px 14px; display: flex; align-items: center; gap: 12px;
  border: 0; border-radius: 12px; color: var(--ink-soft); background: transparent; text-align: left; font-weight: 650;
  transition: .18s ease;
}
.nav-item span { width: 24px; color: #8a9a95; font-size: 18px; text-align: center; }
.nav-item:hover { color: var(--green-900); background: var(--green-50); }
.nav-item.active { color: white; background: var(--green-900); box-shadow: 0 9px 22px rgba(13,59,50,.18); }
.nav-item.active span { color: var(--gold); }
.sidebar-note { padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--green-50); }
.sidebar-note span, .sidebar-note strong { display: block; }
.sidebar-note span { color: var(--ink-soft); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; }
.sidebar-note strong { margin-top: 5px; font-size: 13px; }

.content { min-width: 0; padding: 34px clamp(22px, 3vw, 48px) 70px; }
.view { display: none; max-width: 1460px; margin: 0 auto; animation: enter .22s ease-out; }
.view.active { display: block; }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.page-heading, .section-heading, .panel-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.page-heading { margin-bottom: 27px; }
.page-heading h1 { margin: 2px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(29px, 3vw, 42px); font-weight: 600; letter-spacing: -.025em; }
.eyebrow { margin: 0; color: var(--green-700); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.section-heading { margin: 32px 0 16px; }
.section-heading h2, .panel h2 { margin: 0; font-size: 18px; }
.section-heading p, .panel-header p { margin: 5px 0 0; color: var(--ink-soft); font-size: 13px; }
.legend { display: flex; gap: 17px; color: var(--ink-soft); font-size: 12px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; }
.legend-fill { background: var(--green-700); }
.legend-warning { background: var(--warning); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card {
  position: relative; min-height: 122px; padding: 20px; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 8px 26px rgba(23,53,47,.045);
}
.stat-card::after { content: ""; position: absolute; width: 76px; height: 76px; right: -23px; bottom: -27px; border-radius: 50%; background: var(--green-50); }
.stat-card.warning::after { background: #f9ead9; }
.stat-label { color: var(--ink-soft); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.stat-value { margin-top: 13px; display: block; font-family: Georgia, serif; font-size: 31px; line-height: 1; }
.stat-note { margin-top: 7px; display: block; color: var(--ink-soft); font-size: 12px; }

.silo-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); gap: 14px; }
.silo-card {
  min-height: 237px; padding: 18px; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 8px 24px rgba(23,53,47,.04);
}
.silo-card.has-warning { border-color: #e8c99f; }
.silo-head { display: flex; justify-content: space-between; gap: 10px; }
.silo-code { font-family: Georgia, serif; font-size: 22px; font-weight: 600; }
.silo-role { margin-top: 4px; color: var(--ink-soft); font-size: 11px; line-height: 1.3; }
.state-pill { height: fit-content; padding: 4px 7px; border-radius: 999px; color: var(--green-800); background: var(--green-100); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.state-pill.draft, .state-pill.warning { color: #91531b; background: #fae8cf; }
.silo-vessel { position: relative; width: 62px; height: 91px; margin: 17px auto 12px; overflow: hidden; border: 2px solid #abc0b9; border-radius: 6px 6px 19px 19px; background: #edf2ee; }
.silo-vessel::before { content: ""; position: absolute; z-index: 2; inset: 7px 6px auto; height: 1px; background: rgba(255,255,255,.65); box-shadow: 0 20px rgba(255,255,255,.4), 0 40px rgba(255,255,255,.3); }
.silo-fill { position: absolute; inset: auto 0 0; min-height: 0; background: linear-gradient(180deg, #79a28f, var(--green-700)); transition: height .45s ease; }
.silo-data { margin-top: auto; }
.silo-material { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 700; }
.silo-material span:last-child { color: var(--green-700); }
.progress { height: 5px; margin: 9px 0 7px; overflow: hidden; border-radius: 99px; background: #e5ebe7; }
.progress span { display: block; height: 100%; border-radius: inherit; background: var(--green-700); }
.silo-caption { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-soft); font-size: 10px; }
.warning-line { margin-top: 9px; padding-top: 9px; border-top: 1px solid #f0dfca; color: #9b5a20; font-size: 10px; font-weight: 700; }

.panel { min-width: 0; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.panel-header { margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.step-badge { width: 37px; height: 37px; display: grid; place-items: center; flex: none; border-radius: 50%; color: var(--green-900); background: var(--gold-soft); font-size: 12px; font-weight: 900; }
.split-layout { display: grid; grid-template-columns: minmax(330px, .78fr) minmax(430px, 1.22fr); gap: 20px; align-items: start; }
.catalog-grid, .report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.catalog-grid > :last-child { grid-column: 1 / -1; }
.compact { box-shadow: 0 8px 26px rgba(23,53,47,.045); }

.form-panel { display: grid; gap: 15px; }
.form-grid { display: grid; gap: 13px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.action-row { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
label { min-width: 0; display: grid; gap: 7px; color: #4c635d; font-size: 12px; font-weight: 750; }
input, select, textarea {
  width: 100%; min-width: 0; border: 1px solid #ced9d3; border-radius: 10px; outline: none;
  color: var(--ink); background: #fff; transition: .15s ease;
}
input, select { height: 43px; padding: 0 12px; }
textarea { padding: 11px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green-700); box-shadow: 0 0 0 3px rgba(29,104,87,.1); }
input::placeholder, textarea::placeholder { color: #a1aeaa; }
label.hidden { display: none; }
.hidden { display: none !important; }
details { border: 1px solid var(--line); border-radius: 11px; background: #fafbf8; }
summary { padding: 12px; color: var(--green-800); font-size: 12px; font-weight: 800; cursor: pointer; }
.details-content { padding: 3px 12px 13px; }
.checkbox { min-height: 43px; display: flex; align-items: center; gap: 9px; padding-top: 19px; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--green-700); }

.button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 10px; font-size: 13px; font-weight: 800; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .58; cursor: wait; transform: none; }
.button.primary { color: white; background: var(--green-800); box-shadow: 0 8px 18px rgba(21,80,68,.16); }
.button.primary:hover { background: var(--green-900); }
.button.secondary { color: var(--green-800); border: 1px solid #bfd0c9; background: rgba(255,255,255,.7); }
.button.wide { width: 100%; min-height: 45px; margin-top: 2px; }

.operation-list, .registry-list, .route-list, .model-list, .material-list, .process-list, .document-list, .user-list { display: grid; gap: 10px; }
.list-card { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcf9; }
.list-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 13px; }
.list-card strong { font-size: 14px; }
.list-card p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.45; }
.list-card-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 11px; color: var(--ink-soft); font-size: 11px; }
.mass-value { flex: none; color: var(--green-700); font-family: Georgia, serif; font-size: 20px; font-weight: 700; }
.operation-icon { width: 34px; height: 34px; display: grid; place-items: center; flex: none; border-radius: 10px; color: var(--green-800); background: var(--green-100); font-size: 18px; }
.operation-main { display: flex; gap: 11px; min-width: 0; }
.route-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 12px; }
.route-flow span { padding: 5px 8px; border-radius: 7px; color: var(--green-800); background: var(--green-50); font-size: 11px; font-weight: 700; }
.route-flow i { color: #8ba097; font-style: normal; }
.tag-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 3px; }
.tag { padding: 6px 9px; border: 1px solid #d5e1db; border-radius: 999px; color: var(--green-800); background: var(--green-50); font-size: 11px; font-weight: 700; }
.material-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.material-row strong { font-size: 13px; }
.material-row span { color: var(--ink-soft); font-size: 11px; }
.edit-button { padding: 5px 8px; border: 1px solid #ccd9d3; border-radius: 7px; color: var(--green-800); background: white; font-size: 10px; font-weight: 800; }
.danger-button { color: var(--danger); border-color: #e4c3c0; }
.card-actions { display: grid; justify-items: end; gap: 7px; }
.balance-line { margin-top: 12px; padding: 10px; display: flex; flex-wrap: wrap; gap: 5px 12px; border-radius: 9px; color: var(--green-800); background: var(--green-50); font-size: 11px; font-weight: 750; }
.balance-preview { padding: 11px 12px; border: 1px solid #bcd5c8; border-radius: 10px; color: var(--green-800); background: var(--green-50); font-size: 12px; font-weight: 800; }
.balance-preview.invalid { color: #985518; border-color: #e6c08f; background: #fff2df; }
.report-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.inline-editor { margin-top: 14px; display: grid; grid-template-columns: 150px 110px minmax(170px, 1fr) auto; gap: 9px; align-items: center; }
.inline-editor .checkbox { min-height: 40px; padding: 0; }
.empty-state { grid-column: 1 / -1; padding: 36px 22px; border: 1px dashed #becdc7; border-radius: var(--radius); color: var(--ink-soft); background: rgba(255,255,255,.5); text-align: center; }
.empty-state strong { display: block; margin-bottom: 7px; color: var(--ink); font-size: 16px; }
.empty-state p { max-width: 490px; margin: 0 auto; font-size: 13px; line-height: 1.55; }

.toast { position: fixed; z-index: 100; right: 22px; bottom: 24px; max-width: min(420px, calc(100vw - 44px)); padding: 13px 16px; border-radius: 11px; color: white; background: var(--green-900); box-shadow: 0 15px 40px rgba(9,46,39,.3); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .22s ease; font-size: 13px; font-weight: 700; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }
.mobile-nav { display: none; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-layout { grid-template-columns: 1fr; }
  .catalog-grid { grid-template-columns: 1fr; }
  .report-grid { grid-template-columns: 1fr; }
  .catalog-grid > :last-child { grid-column: auto; }
}

@media (max-width: 780px) {
  .topbar { height: 62px; padding: 0 17px; }
  .brand-mark { width: 37px; height: 37px; border-radius: 11px; }
  .brand small { display: none; }
  .system-state, .user-name { display: none; }
  .app-shell { display: block; min-height: calc(100vh - 62px); }
  .sidebar { display: none; }
  .content { padding: 25px 15px 96px; }
  .page-heading { margin-bottom: 20px; }
  .page-heading h1 { font-size: 30px; }
  .panel { padding: 18px; border-radius: 15px; box-shadow: 0 8px 25px rgba(23,53,47,.055); }
  .mobile-nav {
    position: fixed; z-index: 30; inset: auto 0 0; height: calc(66px + env(safe-area-inset-bottom));
    padding: 7px 8px env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid #ccd9d3; background: rgba(255,254,250,.96); backdrop-filter: blur(16px);
  }
  .mobile-nav button { display: grid; place-items: center; align-content: center; gap: 2px; border: 0; color: #72837e; background: transparent; font-size: 10px; font-weight: 750; }
  .mobile-nav button span { font-size: 19px; line-height: 1; }
  .mobile-nav button.active { color: var(--green-800); }
  .mobile-nav button.active span { color: var(--green-700); }
  .toast { right: 15px; bottom: 80px; }
}

@media (max-width: 560px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .stat-card { min-height: 109px; padding: 15px; border-radius: 14px; }
  .stat-value { font-size: 27px; }
  .stat-note { font-size: 10px; }
  .section-heading { align-items: flex-end; }
  .legend { display: none; }
  .silo-board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .silo-card { min-height: 221px; padding: 13px; border-radius: 14px; }
  .silo-code { font-size: 19px; }
  .silo-vessel { margin-top: 13px; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .form-grid.action-row { grid-template-columns: 1fr; }
  .form-grid.action-row .button { min-height: 43px; }
  .checkbox { padding-top: 0; }
  .panel-header { align-items: flex-start; }
  .list-card-meta { display: grid; gap: 4px; }
  .inline-editor { grid-template-columns: 1fr; }
  .auth-screen { padding: 12px; }
  .auth-card { padding: 25px 20px; border-radius: 18px; }
}
