:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-alt: #f9fafb;
    --text: #17191c;
    --muted: #667085;
    --line: #e4e7ec;
    --brand: #d71920;
    --brand-dark: #a80d13;
    --black: #121212;
    --success: #137a4e;
    --warning: #a15c00;
    --danger: #b42318;
    --info: #175cd3;
    --radius: 14px;
    --shadow: 0 8px 28px rgba(16, 24, 40, 0.08);
}

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

.topbar {
    min-height: 76px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 24px;
    padding: 10px 28px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.brand img { width: 74px; height: 52px; object-fit: contain; }
.brand span { display: grid; line-height: 1.1; }
.brand strong { font-size: 18px; letter-spacing: .08em; }
.brand small { color: var(--muted); font-size: 12px; margin-top: 4px; }
.main-nav { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; }
.main-nav a { padding: 10px 12px; border-radius: 9px; color: #3d4148; font-size: 14px; font-weight: 650; }
.main-nav a:hover { background: #f1f3f5; color: var(--black); }
.main-nav .nav-primary { background: var(--brand); color: white; }
.main-nav .nav-primary:hover { background: var(--brand-dark); color: white; }
.user-menu { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.link-button { border: 0; background: none; color: var(--brand-dark); cursor: pointer; padding: 4px; font-weight: 650; }
.menu-toggle { display: none; border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 11px; }

.page-shell { width: min(1480px, calc(100% - 36px)); margin: 0 auto; padding: 30px 0 64px; }
.auth-shell { width: 100%; min-height: 100vh; padding: 0; display: grid; place-items: center; background: linear-gradient(135deg, #111 0%, #2a1112 45%, #d71920 160%); }
.page-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; margin-bottom: 24px; }
.page-header h1 { margin: 0; font-size: clamp(26px, 4vw, 40px); letter-spacing: -.03em; }
.page-header p { margin: 8px 0 0; color: var(--muted); max-width: 800px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; padding: 10px 15px; font-weight: 700; cursor: pointer; min-height: 42px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn-dark { background: var(--black); color: white; }
.btn-small { min-height: 34px; padding: 7px 11px; font-size: 13px; }

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 22px; }
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.card-header h2, .card-header h3 { margin: 0; font-size: 18px; }
.card-footer { padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface-alt); border-radius: 0 0 var(--radius) var(--radius); }
.stat-card { padding: 22px; position: relative; overflow: hidden; }
.stat-card::after { content: ""; width: 70px; height: 70px; border-radius: 50%; background: rgba(215,25,32,.08); position: absolute; right: -18px; top: -18px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 36px; font-weight: 800; margin-top: 8px; letter-spacing: -.04em; }
.stat-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 30px 0 14px; }
.section-title h2 { margin: 0; font-size: 21px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-alt); }
tbody tr:hover { background: #fcfcfd; }
tbody tr:last-child td { border-bottom: 0; }
.table-link { font-weight: 750; color: var(--black); }
.table-link:hover { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 750; background: #eef2f6; color: #344054; }
.status-active, .status-resolved, .status-completed, .status-paid { background: #dcfae6; color: #087443; }
.status-new, .status-open { background: #e7f0ff; color: #175cd3; }
.status-review, .status-scheduled, .status-in_progress { background: #fff2cc; color: #7a4d00; }
.status-waiting, .status-service_due { background: #ffead5; color: #93370d; }
.status-fault, .status-urgent, .status-cancelled, .status-offline { background: #fee4e2; color: #b42318; }
.priority-low { background: #f2f4f7; color: #475467; }
.priority-normal { background: #e7f0ff; color: #175cd3; }
.priority-high { background: #ffead5; color: #93370d; }
.priority-urgent { background: #fee4e2; color: #b42318; }

.filters { display: grid; grid-template-columns: minmax(200px, 1fr) repeat(2, minmax(160px, 220px)) auto; gap: 10px; margin-bottom: 18px; background: var(--surface); padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.form-card { max-width: 920px; margin: 0 auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-group { display: grid; gap: 7px; }
.form-group.full, .form-actions { grid-column: 1 / -1; }
.form-group label { font-weight: 700; font-size: 14px; }
.form-control { width: 100%; min-height: 44px; border: 1px solid #cfd4dc; border-radius: 9px; padding: 10px 12px; background: white; color: var(--text); }
textarea.form-control { resize: vertical; min-height: 110px; }
.form-control:focus { outline: 3px solid rgba(215,25,32,.12); border-color: var(--brand); }
.helptext, .help-text { color: var(--muted); font-size: 12px; }
.errorlist { margin: 0; padding: 8px 12px; border-radius: 8px; list-style: none; color: var(--danger); background: #fff1f0; font-size: 13px; }
.form-actions { display: flex; gap: 10px; padding-top: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 9px; }
.checkbox-row input { width: 18px; height: 18px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.definition-list { display: grid; grid-template-columns: minmax(130px, 180px) 1fr; gap: 0; }
.definition-list dt, .definition-list dd { margin: 0; padding: 11px 0; border-bottom: 1px solid var(--line); }
.definition-list dt { color: var(--muted); font-size: 13px; font-weight: 650; padding-right: 18px; }
.definition-list dd { font-weight: 550; }
.prose { white-space: pre-line; line-height: 1.6; }
.empty-state { padding: 44px 24px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.item-list { display: grid; }
.item-row { display: flex; justify-content: space-between; gap: 18px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.item-row:last-child { border-bottom: 0; }
.item-row strong { display: block; margin-bottom: 4px; }

.auth-card { width: min(440px, calc(100% - 34px)); background: white; border-radius: 20px; box-shadow: 0 24px 70px rgba(0,0,0,.32); padding: 32px; }
.auth-logo { display: block; width: 210px; height: 128px; object-fit: contain; margin: 0 auto 18px; }
.auth-card h1 { margin: 0; text-align: center; font-size: 28px; }
.auth-card > p { text-align: center; color: var(--muted); margin: 8px 0 24px; }
.auth-card .form-group { margin-bottom: 16px; }
.auth-card .btn { width: 100%; }
.auth-note { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); text-align: center; color: var(--muted); font-size: 12px; }

.messages { display: grid; gap: 8px; margin-bottom: 18px; }
.message { padding: 13px 16px; border-radius: 10px; background: #e7f0ff; color: #175cd3; border: 1px solid #b2ccff; }
.message.success { background: #dcfae6; color: #087443; border-color: #abefc6; }
.message.error { background: #fee4e2; color: #b42318; border-color: #fecdca; }
.breadcrumbs { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; margin-bottom: 14px; flex-wrap: wrap; }
.breadcrumbs a:hover { color: var(--brand); }
.kicker { text-transform: uppercase; font-size: 12px; letter-spacing: .08em; color: var(--brand); font-weight: 800; }
.logo-watermark { width: 170px; max-height: 100px; object-fit: contain; opacity: .9; }

@media (max-width: 1120px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar { grid-template-columns: auto auto 1fr auto; gap: 12px; }
    .menu-toggle { display: block; }
    .main-nav { display: none; position: absolute; top: 76px; left: 18px; right: 18px; background: white; border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 12px; padding: 10px; justify-content: flex-start; }
    .main-nav.is-open { display: grid; }
    .main-nav a { width: 100%; }
}

@media (max-width: 760px) {
    .topbar { padding: 9px 14px; grid-template-columns: auto auto 1fr; }
    .brand { min-width: 0; }
    .brand img { width: 60px; height: 45px; }
    .brand span { display: none; }
    .user-menu > span { display: none; }
    .user-menu { justify-self: end; }
    .page-shell { width: min(100% - 22px, 1480px); padding-top: 20px; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .filters { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .definition-list { grid-template-columns: 1fr; }
    .definition-list dt { border-bottom: 0; padding-bottom: 2px; }
    .definition-list dd { padding-top: 2px; }
    th, td { padding: 12px; }
}

@media print {
    .topbar, .actions, .no-print, .messages { display: none !important; }
    body, html { background: white; }
    .page-shell { width: 100%; padding: 0; }
    .card { box-shadow: none; }
}
