:root {
  --navy: #17324d;
  --navy-dark: #0d2237;
  --blue: #2f6fed;
  --blue-soft: #eaf1ff;
  --green: #177a55;
  --green-soft: #e7f6ef;
  --amber: #956100;
  --amber-soft: #fff5d8;
  --red: #b42318;
  --red-soft: #feeceb;
  --ink: #1c2733;
  --muted: #657386;
  --line: #dce3ea;
  --surface: #ffffff;
  --background: #f4f7fa;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(23, 50, 77, 0.08);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--background); }
body { margin: 0; min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar { position: sticky; top: 0; z-index: 20; min-height: 68px; display: flex; align-items: center; gap: 28px; padding: 0 4vw; color: #fff; background: var(--navy-dark); box-shadow: 0 3px 14px rgba(0,0,0,.14); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 35px; height: 35px; display: inline-grid; place-items: center; color: #fff; background: var(--blue); border-radius: 10px; }
.brand-centered { justify-content: center; color: var(--navy); margin-bottom: 20px; }
.nav { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.nav a { color: #cbd9e6; padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 650; }
.nav a:hover, .nav a.active { color: #fff; background: rgba(255,255,255,.10); text-decoration: none; }
.menu-button { display: none; margin-left: auto; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.4); padding: 8px 11px; border-radius: 8px; }

.shell { width: min(1320px, 92vw); margin: 28px auto 60px; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 10% 10%, #edf3ff, transparent 35%), var(--background); }
.auth-card { width: min(460px, 100%); padding: 34px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.install-card { width: min(780px, 100%); }

h1, h2, h3 { color: var(--navy-dark); letter-spacing: -.025em; }
h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 36px); }
h2 { margin: 0 0 16px; font-size: 21px; }
h3 { margin: 0; font-size: 16px; }
p { line-height: 1.55; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 3px 14px rgba(23,50,77,.04); }
.card-pad { padding: 24px; }
.card + .card { margin-top: 18px; }
.stack > * + * { margin-top: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 24px; }
.stat { padding: 20px; }
.stat .number { margin-top: 8px; color: var(--navy-dark); font-size: 34px; line-height: 1; font-weight: 800; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.dashboard-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.form-grid.two-col { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: var(--navy-dark); font-size: 13px; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--ink); background: #fff; border: 1px solid #c8d2dc; border-radius: 9px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,111,237,.13); }
textarea { min-height: 100px; resize: vertical; }
label small { color: var(--muted); font-weight: 500; }
.field-with-action { display: flex; gap: 7px; }
.field-with-action .button { flex: 0 0 auto; }
.filter-bar { display: grid; grid-template-columns: 1.2fr 1fr 1.2fr .8fr 1fr 1fr auto; gap: 10px; align-items: end; }

.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; gap: 7px; padding: 9px 14px; border: 1px solid transparent; border-radius: 9px; font-weight: 750; font-size: 14px; line-height: 1.1; }
.button:hover { text-decoration: none; filter: brightness(.97); }
.button.primary { color: #fff; background: var(--blue); }
.button.secondary { color: var(--navy); background: #fff; border-color: #bac7d3; }
.button.danger { color: var(--red); background: var(--red-soft); border-color: #f6c9c5; }
.button.large { min-height: 48px; padding: 12px 20px; }
.button.tiny { min-height: 32px; padding: 6px 9px; font-size: 12px; }
.button.wide { width: 100%; }

.alert { margin-bottom: 18px; padding: 13px 16px; border-radius: 10px; border: 1px solid; }
.alert-success { color: var(--green); background: var(--green-soft); border-color: #b9e3d0; }
.alert-error { color: var(--red); background: var(--red-soft); border-color: #f4c7c3; }
.alert-warning { color: var(--amber); background: var(--amber-soft); border-color: #ecd994; }

.table-wrap { 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: middle; font-size: 14px; }
th { color: var(--muted); background: #f8fafc; font-size: 12px; letter-spacing: .035em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { padding: 34px 20px; color: var(--muted); text-align: center; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge-pending { color: var(--amber); background: var(--amber-soft); }
.badge-in_progress { color: #2457ad; background: var(--blue-soft); }
.badge-completed { color: var(--green); background: var(--green-soft); }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 15px 18px; border-top: 1px solid var(--line); }

.record-hero { display: grid; grid-template-columns: 1fr auto; gap: 18px; padding: 22px; color: #fff; background: var(--navy); border-radius: var(--radius); }
.record-hero h1 { color: #fff; }
.record-hero .muted { color: #c9d7e4; }
.info-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px; overflow: hidden; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); }
.info-grid.summary-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
.info-grid.component-summary { grid-template-columns: repeat(3, minmax(0,1fr)); }
.info-cell { min-height: 86px; padding: 16px; background: #fff; }
.info-cell .key { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; }
.info-cell .value { color: var(--navy-dark); font-weight: 750; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.component-admin, .component-entry { margin-top: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; }
.component-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; background: #f7f9fc; border-bottom: 1px solid var(--line); }
.component-form-grid { display: grid; grid-template-columns: .8fr 1.5fr; gap: 18px; margin-top: 20px; }
.subform { padding: 18px; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; }
.material-entry-row { display: grid; grid-template-columns: 1.3fr .8fr 1fr; gap: 14px; align-items: end; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.material-entry-row:last-child { border-bottom: 0; }
.material-description { display: grid; gap: 3px; }
.material-description span, .material-description small { color: var(--muted); }

.import-steps { display: flex; gap: 10px; margin-bottom: 20px; }
.step { flex: 1; padding: 12px; color: var(--muted); background: #eef2f6; border-radius: 9px; font-size: 13px; font-weight: 750; text-align: center; }
.step.active { color: #fff; background: var(--blue); }
.row-error { background: #fff2f1; }
.error-text { color: var(--red); font-size: 12px; }

.report { width: min(900px, 100%); margin: 0 auto; padding: 42px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.report-header { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 20px; border-bottom: 2px solid var(--navy); }
.report-title { margin: 0; font-size: 28px; }
.report-meta { text-align: right; }
.report-section { margin-top: 24px; }
.report-section h2 { padding-bottom: 8px; border-bottom: 1px solid var(--line); font-size: 15px; text-transform: uppercase; letter-spacing: .06em; }
.report-details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 24px; }
.report-field .key { display: block; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.report-field .value { display: block; margin-top: 3px; font-weight: 700; }
.report-results { display: grid; grid-template-columns: repeat(2, 1fr); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.report-result { display: flex; justify-content: space-between; gap: 16px; padding: 10px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.report-component { margin-top: 16px; break-inside: avoid; }
.report-component h3 { margin-bottom: 8px; }
.report-material-table { border: 1px solid var(--line); }
.report-material-table th, .report-material-table td { padding: 9px 10px; border-right: 1px solid var(--line); }
.signature-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 60px; margin-top: 54px; }
.signature { padding-top: 10px; border-top: 1px solid #68727c; color: var(--muted); font-size: 12px; }

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2,1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: repeat(3, 1fr); }
  .filter-bar .actions { grid-column: 1/-1; }
  .info-grid, .info-grid.component-summary { grid-template-columns: repeat(2,1fr); }
  .component-form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { min-height: 62px; padding: 0 18px; }
  .menu-button { display: inline-flex; }
  .nav { display: none; position: absolute; top: 62px; left: 12px; right: 12px; padding: 10px; flex-direction: column; align-items: stretch; background: var(--navy-dark); border-radius: 0 0 12px 12px; box-shadow: var(--shadow); }
  .nav.open { display: flex; }
  .shell { width: min(94vw, 1320px); margin-top: 20px; }
  .page-head { flex-direction: column; }
  .page-head .actions, .page-head .button { width: 100%; }
  .stats, .form-grid, .form-grid.two-col, .filter-bar, .result-grid, .info-grid, .info-grid.component-summary, .report-details { grid-template-columns: 1fr; }
  .component-head { align-items: flex-start; flex-direction: column; }
  .material-entry-row { grid-template-columns: 1fr; }
  .record-hero { grid-template-columns: 1fr; }
  .record-hero .actions { align-items: stretch; flex-direction: column; }
  .card-pad { padding: 18px; }
  .auth-card { padding: 24px 20px; }
  .report { padding: 24px 18px; }
  .report-header { flex-direction: column; }
  .report-meta { text-align: left; }
  .report-results { grid-template-columns: 1fr; }
  .signature-row { gap: 30px; }
}

@media print {
  @page { size: A4; margin: 13mm; }
  html, body { background: #fff; }
  .no-print { display: none !important; }
  .shell { width: 100%; margin: 0; }
  .report { width: 100%; padding: 0; border: 0; box-shadow: none; }
  .report-title { font-size: 23px; }
  .report-section { break-inside: auto; }
  .report-details, .report-results, .report-component { break-inside: avoid; }
  .report-material-table { font-size: 9pt; }
  .report-material-table th, .report-material-table td { padding: 6px 7px; }
}
