:root {
  --ink: #18242c;
  --muted: #68767f;
  --paper: #fff;
  --canvas: #f3f5f5;
  --line: #dce2e4;
  --navy: #182a33;
  --navy-light: #243a44;
  --red: #b9342f;
  --red-dark: #962823;
  --blue: #356f99;
  --green: #2f7357;
  --amber: #9a641b;
  --shadow: 0 12px 32px rgba(24, 35, 43, .07);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { letter-spacing: -.025em; }
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: 10px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }

.login-screen { display: grid; min-height: 100vh; grid-template-columns: minmax(420px, .78fr) 1.22fr; background: #fff; }
.login-panel { display: flex; max-width: 610px; flex-direction: column; justify-content: center; padding: 70px clamp(32px, 7vw, 105px); }
.login-brand, .brand { display: flex; align-items: center; gap: 12px; }
.login-brand { margin-bottom: 70px; }
.brand-mark { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 9px; color: #fff; font-size: 12px; font-weight: 900; letter-spacing: -.03em; background: var(--red); }
.login-brand strong, .login-brand span, .brand strong, .brand span { display: block; }
.login-brand span, .brand span { margin-top: 2px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.login-panel h1 { max-width: 430px; margin-bottom: 0; font-size: clamp(44px, 5vw, 72px); line-height: 1; }
.login-lead { margin: 22px 0 30px; color: var(--muted); line-height: 1.65; }
.login-panel form { display: grid; gap: 16px; }
.login-aside { display: flex; align-items: end; padding: 75px; color: #fff; background: radial-gradient(circle at 80% 20%, rgba(185,52,47,.45), transparent 28%), linear-gradient(140deg, #213842, #13232b 70%); }
.login-aside > div { max-width: 690px; }
.login-aside h2 { margin-bottom: 0; font-size: clamp(40px, 5vw, 72px); line-height: 1.06; }
.login-aside ul { display: grid; gap: 12px; margin: 30px 0 0; padding: 0; color: #d0d9dc; list-style: none; }
.login-aside li::before { margin-right: 10px; color: #df7972; content: "✓"; }

.field span, .file-drop > span { display: block; margin-bottom: 6px; color: #5f6b73; font-size: 10px; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.field input, .field select, .field textarea, .search-box input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #cfd6da;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
.field textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus, .search-box input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(53,111,153,.11); }
.primary-button, .secondary-button, .danger-button, .small-button {
  display: inline-flex;
  min-height: 43px;
  align-items: center;
  justify-content: center;
  padding: 0 17px;
  border-radius: 6px;
  font-weight: 800;
  text-decoration: none;
}
.primary-button { border: 0; color: #fff; background: var(--red); }
.primary-button:hover { background: var(--red-dark); }
.secondary-button { border: 1px solid #cfd6da; color: var(--ink); background: #fff; }
.secondary-button:hover { border-color: #aeb9be; background: #fafafa; }
.secondary-button[aria-disabled="true"] { cursor: not-allowed; color: #89949a; border-color: #dde2e4; background: #f1f3f4; opacity: .7; }
.danger-button { border: 1px solid #e2b6b3; color: #9c2d28; background: #fff; }
.small-button { min-height: 35px; padding-inline: 12px; border: 1px solid #d2dadd; color: var(--ink); font-size: 11px; background: #fff; }
.link-button { min-height: 36px; padding-inline: 13px; font-size: 11px; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 5; display: flex; width: 245px; flex-direction: column; padding: 25px 17px; color: #fff; background: var(--navy); }
.brand { padding: 0 8px 24px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand span { color: #9eacb4; }
.sidebar nav { display: grid; gap: 6px; margin-top: 22px; }
.sidebar nav button { display: flex; min-height: 45px; align-items: center; gap: 12px; padding: 0 12px; border: 0; border-radius: 7px; color: #aebbc2; text-align: left; background: transparent; }
.sidebar nav button:hover, .sidebar nav button.active { color: #fff; background: rgba(255,255,255,.09); }
.nav-icon { display: inline-grid; width: 23px; height: 23px; place-items: center; border-radius: 5px; color: #e6b1ad; font-size: 16px; background: rgba(255,255,255,.06); }
.sidebar-spacer { flex: 1; }
.user-card { padding: 15px; border: 1px solid rgba(255,255,255,.1); border-radius: 8px; background: rgba(255,255,255,.04); }
.user-card span, .user-card strong { display: block; }
.user-card span { color: #94a3ab; font-size: 9px; font-weight: 850; text-transform: uppercase; }
.user-card strong { overflow: hidden; margin: 6px 0 12px; font-size: 12px; text-overflow: ellipsis; }
.user-card button { padding: 0; border: 0; color: #e6b1ad; font-size: 11px; background: transparent; }

.main-content { min-height: 100vh; margin-left: 245px; padding: 34px clamp(25px, 4vw, 58px) 60px; }
.main-content > section { width: min(100%, 1500px); margin-inline: auto; }
.topbar, .panel-heading, .section-actionbar, .dialog-actions, .header-actions { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.topbar { margin-bottom: 25px; }
.topbar h1 { margin-bottom: 0; font-size: clamp(30px, 4vw, 43px); }
.topbar-lead { max-width: 720px; margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.company-heading { align-items: center; }
.company-heading-controls { display: flex; align-items: center; justify-content: flex-end; gap: 14px; flex-wrap: wrap; }
.recommended-button { min-height: 37px; padding-inline: 13px; font-size: 11px; white-space: nowrap; }
.back-button { margin: 0 0 13px; padding: 0; border: 0; color: var(--blue); font-size: 12px; font-weight: 750; background: transparent; }
.back-button:hover { text-decoration: underline; }


.content-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: var(--shadow); }
.panel-heading { padding: 20px 21px 14px; }
.panel-heading h2, .section-actionbar h2 { margin-bottom: 0; font-size: 22px; }
.panel-heading p, .section-actionbar p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.search-box { position: relative; width: min(350px, 40vw); }
.search-box span { position: absolute; top: 50%; left: 13px; color: #748087; transform: translateY(-50%); }
.search-box input { padding-left: 37px; }

.company-panel { display: flex; align-items: center; gap: 20px; margin-bottom: 17px; padding: 17px 20px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 5px 16px rgba(25,36,44,.03); }
.company-summary { display: grid; flex: 1; grid-template-columns: .55fr 1.2fr 1.2fr 1.4fr; gap: 22px; }
.company-summary span, .company-summary strong { display: block; }
.company-summary > div > span { margin-bottom: 4px; color: var(--muted); font-size: 9px; font-weight: 850; text-transform: uppercase; }
.company-summary strong { font-size: 12px; line-height: 1.5; }
.branch-list { display: flex; flex-wrap: wrap; gap: 5px; }
.branch-chip { display: inline-flex; min-height: 26px; align-items: center; padding: 0 8px; border: 1px solid #dbe1e3; border-radius: 14px; color: #56636b; font-size: 10px; background: #f8f9f9; }
button.branch-chip:hover { color: var(--red); border-color: #e2b7b4; background: #fff; }

.section-tabs { display: flex; gap: 4px; margin: 0; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: #eef1f2; }
.section-tabs button { min-height: 35px; padding: 0 11px; border: 0; border-radius: 5px; color: #5f6c74; font-size: 11px; font-weight: 800; background: transparent; }
.section-tabs button.active { color: var(--ink); background: #fff; box-shadow: 0 3px 10px rgba(24,35,43,.08); }
.section-tabs button span { display: inline-grid; min-width: 18px; height: 18px; margin-left: 5px; place-items: center; border-radius: 9px; color: #fff; font-size: 9px; background: #77858c; }
.section-tabs button.active span { background: var(--red); }
.section-actionbar { margin-bottom: 15px; }

.deadline-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.status-filter select { min-height: 43px; padding: 0 34px 0 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); font-size: 11px; font-weight: 750; background: #fff; }
.visually-hidden { position: absolute !important; overflow: hidden; width: 1px; height: 1px; clip: rect(0 0 0 0); white-space: nowrap; clip-path: inset(50%); }
.branch-tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 21px 12px; border-bottom: 1px solid var(--line); }
.branch-tabs button { flex: 0 0 auto; min-height: 32px; padding: 0 11px; border: 1px solid transparent; border-radius: 6px; color: var(--muted); font-size: 11px; font-weight: 750; background: transparent; }
.branch-tabs button.active, .branch-tabs button:hover { color: var(--ink); border-color: #d6dcdf; background: #f1f3f4; }

.message { margin: 13px 21px 0; padding: 10px 12px; border-radius: 6px; color: #286046; font-size: 12px; background: #e5f2eb; }
.message.error { color: #8f2b26; background: #fae7e5; }
.message.flush { margin: 0; }
.page-message { position: fixed; z-index: 15; top: 20px; right: 25px; max-width: 520px; margin: 0; box-shadow: 0 10px 35px rgba(24,35,43,.18); }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 850px; border-collapse: collapse; }
th, td { padding: 13px 15px; border-bottom: 1px solid #edf0f1; text-align: left; vertical-align: middle; }
th:first-child, td:first-child { padding-left: 21px; }
th { color: #748088; font-size: 9px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; background: #fafbfb; }
td { color: #45525a; font-size: 12px; }
td:first-child { width: 33%; color: var(--ink); }
.companies-table td:first-child { width: 38%; }
.companies-table tr:hover td { background: #fcfdfd; }
.number-cell { font-size: 14px; font-weight: 800; }
.table-detail { display: block; margin-top: 4px; color: #818c92; font-size: 10px; }
.status-badge { display: inline-flex; min-height: 25px; align-items: center; padding: 0 8px; border-radius: 18px; font-size: 10px; font-weight: 850; white-space: nowrap; }
.status-badge.overdue { color: #982d28; background: #fae7e5; }
.status-badge.soon { color: #855610; background: #fff0d6; }
.status-badge.ok { color: #2b684f; background: #e4f2ea; }
.edit-button, .open-button { min-height: 34px; padding: 0 11px; border: 1px solid #d5dbde; border-radius: 6px; color: #59666e; font-size: 10px; font-weight: 800; white-space: nowrap; background: #fff; }
.edit-button:hover, .open-button:hover { color: var(--red); border-color: #e4b9b6; }
.empty-state { display: grid; min-height: 220px; place-items: center; align-content: center; gap: 6px; color: var(--muted); }
.empty-state strong { color: var(--ink); }

.document-grid { display: grid; gap: 12px; }
.document-card { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; align-items: center; gap: 18px; padding: 19px 21px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 5px 18px rgba(24,35,43,.04); }
.document-card.info { border-left: 4px solid var(--blue); }
.document-card.file { border-left: 4px solid var(--red); }
.document-icon { display: grid; width: 54px; height: 54px; place-items: center; border-radius: 9px; color: var(--red); font-size: 11px; font-weight: 900; background: #f8e8e7; }
.document-card.info .document-icon { color: var(--blue); font-family: Georgia, serif; font-size: 26px; font-style: italic; background: #e8f0f6; }
.document-kind { color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.document-body h3 { margin: 3px 0 7px; font-size: 17px; }
.document-body p { max-width: 900px; margin: 0 0 9px; color: #4f5d65; font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
.document-body small { color: #849097; font-size: 10px; }
.document-card-actions { display: flex; align-items: center; gap: 8px; }
.document-card-actions .secondary-button { min-height: 36px; padding-inline: 13px; font-size: 11px; }
.panel-empty { min-height: 300px; border: 1px dashed #ccd5d9; border-radius: 10px; background: rgba(255,255,255,.6); }
.global-document-list { display: grid; gap: 9px; margin: 18px 0; }
.global-document-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: #f8f9f9; }
.global-document-card strong, .global-document-card small { display: block; }
.global-document-card strong { margin-bottom: 4px; font-size: 13px; }
.global-document-card small { color: var(--muted); font-size: 10px; }
.global-document-actions { display: flex; flex: 0 0 auto; gap: 7px; }
.global-document-upload { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.global-document-upload .file-drop { margin-top: 12px; }

dialog { width: min(720px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 12px; color: var(--ink); box-shadow: 0 28px 80px rgba(9,18,24,.3); }
dialog::backdrop { background: rgba(13,23,29,.65); backdrop-filter: blur(3px); }
.form-dialog { padding: 28px; }
.compact-dialog { width: min(560px, calc(100% - 28px)); }
.form-dialog h2 { margin-bottom: 12px; font-size: 30px; }
.form-dialog > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }
.form-dialog form { display: grid; gap: 16px; margin-top: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.field-wide { grid-column: 1/-1; }
.form-note { margin: -4px 0 0 !important; color: var(--muted); font-size: 11px; }
.dialog-actions { margin-top: 8px; padding-top: 17px; border-top: 1px solid var(--line); }
.dialog-close { position: absolute; top: 12px; right: 14px; width: 38px; height: 38px; border: 0; color: var(--muted); font-size: 27px; background: transparent; }
.file-drop { display: grid; min-height: 120px; place-items: center; align-content: center; padding: 18px; border: 2px dashed #cbd4d8; border-radius: 8px; text-align: center; background: #f8fafa; }
.file-drop > span { margin-bottom: 12px; }

@media (max-width: 1100px) {
  .sidebar { width: 215px; }
  .main-content { margin-left: 215px; padding-inline: 24px; }
  .company-summary { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 800px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-panel { max-width: none; padding: 48px 28px; }
  .login-brand { margin-bottom: 48px; }
  .login-aside { min-height: 390px; padding: 45px; }
  .sidebar { position: static; width: 100%; padding: 15px; }
  .sidebar .brand { padding-bottom: 14px; }
  .sidebar nav { display: flex; overflow-x: auto; margin-top: 12px; }
  .sidebar nav button { flex: 0 0 auto; }
  .sidebar-spacer, .user-card { display: none; }
  .main-content { margin-left: 0; padding: 25px 16px 45px; }
  .topbar, .panel-heading, .section-actionbar, .company-panel { align-items: stretch; flex-direction: column; }
  .company-heading-controls, .deadline-toolbar { justify-content: flex-start; }
  .header-actions { align-items: stretch; }
  .header-actions > * { flex: 1; }
  .search-box { width: 100%; }
  .document-card { grid-template-columns: 52px minmax(0, 1fr); }
  .document-card-actions { grid-column: 1 / -1; justify-content: end; }
  .global-document-card { align-items: stretch; flex-direction: column; }
  .global-document-actions { justify-content: flex-end; }
}

@media (max-width: 560px) {
  .login-aside { display: none; }
  .company-summary, .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .section-tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .deadline-toolbar > * { width: 100%; }
  .status-filter select { width: 100%; }
  .header-actions { flex-direction: column; }
  .form-dialog { padding: 25px 18px; }
  .document-card { grid-template-columns: 1fr; }
  .document-icon { width: 48px; height: 48px; }
  .document-card-actions { grid-column: auto; justify-content: start; }
}

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { color: #000; background: #fff; }
  .sidebar, .page-message, .back-button, .company-heading-controls,
  .deadline-toolbar, .branch-tabs, #documents-view, #deadline-actions-heading,
  #deadline-rows td:last-child { display: none !important; }
  .main-content { min-height: auto; margin: 0; padding: 0; }
  .main-content > section { width: 100%; max-width: none; }
  .topbar { margin-bottom: 10px; }
  .topbar h1 { font-size: 25px; }
  .company-panel { margin-bottom: 10px; padding: 10px 12px; border: 1px solid #999; box-shadow: none; }
  .company-summary { grid-template-columns: .6fr 1.4fr 1fr 1fr; }
  .content-panel { overflow: visible; border: 1px solid #999; box-shadow: none; }
  .panel-heading { padding: 10px 12px 6px; }
  table { font-size: 9px; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  th, td { padding: 7px 8px; }
}
