:root {
    --primary: #7352c7;
    --primary-dark: #5e3bb7;
    --secondary: #e44a77;
    --success: #20a779;
    --danger: #d9364f;
    --warning: #f39711;
    --info: #208ea2;
    --text: #475259;
    --muted: #8595a6;
    --border: #dee2e6;
    --background: #f5f7fa;
    --surface: #ffffff;
    --sidebar: #26243b;
    --sidebar-muted: #b8b3d0;
    --shadow: 0 0.5rem 1.25rem rgba(115, 82, 199, 0.14);
    --radius: 12px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--background);
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(420px, 1fr);
    gap: 24px;
    padding: 24px;
    background: var(--surface);
}
.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}
.login-box { width: min(520px, 100%); }
.login-box .form-group { margin-bottom: 18px; }
.login-box .btn-primary { width: 100%; }
.login-logo { width: 132px; margin-bottom: 70px; }
.login-title { font-size: 42px; line-height: 1.1; color: #37373c; margin: 0 0 10px; }
.login-subtitle { color: var(--muted); margin: 0 0 32px; font-size: 16px; }
.login-visual {
    min-height: calc(100vh - 48px);
    border-radius: 18px;
    background: var(--primary);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 56px;
    overflow: hidden;
}
.login-visual h2 { color: white; font-size: 36px; font-weight: 400; margin: 0 0 24px; }
.login-visual img { border-radius: 12px; box-shadow: 0 14px 38px rgba(0,0,0,.18); }
.login-footer { margin-top: 70px; color: var(--muted); }

.installer-page { grid-template-columns: minmax(620px, 1.25fr) minmax(360px, .75fr); }
.installer-box { width: min(760px, 100%); }
.installer-logo { margin-bottom: 34px; }
.installer-section-title { margin: 28px 0 14px; font-size: 17px; color: #37373c; }
.installer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.installer-grid .installer-col-2 { grid-column: span 2; }
.installer-submit { margin-top: 24px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.sidebar {
    background: var(--sidebar);
    color: white;
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; min-height: 56px; padding: 4px 12px 22px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand img { width: 122px; }
.nav { list-style: none; padding: 18px 0 0; margin: 0; }
.nav-item { margin: 4px 0; }
.nav-link, .nav-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 9px;
    color: var(--sidebar-muted);
}
.nav-link:hover, .nav-link.active { color: white; background: rgba(115,82,199,.36); }
.nav-heading { color: #fff; font-weight: 700; padding-bottom: 4px; }
.nav-children { list-style: none; margin: 0 0 8px; padding: 0 0 0 16px; }
.nav-children .nav-link { font-size: 13px; min-height: 38px; }
.nav-mark { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .7; flex: 0 0 auto; }

.main { min-width: 0; }
.topbar {
    height: 72px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-title { font-size: 18px; font-weight: 700; color: #37373c; }
.user-menu { display: flex; align-items: center; gap: 12px; }
.user-avatar { width: 38px; height: 38px; border-radius: 50%; background: rgba(115,82,199,.15); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.user-meta { line-height: 1.25; }
.user-meta small { color: var(--muted); display: block; }
.content { padding: 28px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-title { margin: 0; font-size: 24px; color: #37373c; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 22px; overflow: hidden; }
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { margin: 0; font-size: 17px; color: #37373c; }
.card-body { padding: 22px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.metric-card { padding: 24px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric-label { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
.metric-value { font-size: 34px; color: var(--primary); margin-top: 10px; font-weight: 700; }

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.col-12 { grid-column: span 12; }
.col-9 { grid-column: span 9; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }
.col-2 { grid-column: span 2; }
.form-group { min-width: 0; }
.form-label { display: block; font-weight: 700; margin-bottom: 7px; color: #475259; }
.form-control, .form-select {
    display: block;
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid #cfd6dd;
    border-radius: 8px;
    color: var(--text);
    background: white;
    transition: border-color .15s, box-shadow .15s;
}
textarea.form-control { min-height: 110px; resize: vertical; }
.form-control:focus, .form-select:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(115,82,199,.14); }
.form-control[readonly] { background: #f0f2f5; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 5px; }
.input-unit { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; }
.input-unit .form-control { border-radius: 8px 0 0 8px; }
.input-unit span { display: grid; place-items: center; padding: 0 12px; background: #eef1f4; border: 1px solid #cfd6dd; border-left: 0; border-radius: 0 8px 8px 0; color: var(--muted); }
.option-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.option-card { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.option-card input { accent-color: var(--primary); }
fieldset { border: 0; padding: 0; margin: 0; }
.section-title { margin: 0 0 16px; font-size: 16px; color: #37373c; }
.subsection { padding: 18px; border: 1px solid var(--border); border-radius: 10px; background: #fbfcfd; margin-bottom: 16px; }
.subsection:last-child { margin-bottom: 0; }
.condition-table { width: 100%; border-collapse: collapse; }
.condition-table th, .condition-table td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; }
.condition-table th { background: #f6f6f6; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }
.condition-table tr:last-child td { border-bottom: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 9px 15px; border-radius: 8px; border: 1px solid transparent; font-weight: 700; text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-secondary { background: white; color: var(--primary); border-color: var(--primary); }
.btn-secondary:hover { background: rgba(115,82,199,.08); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { color: white; filter: brightness(.93); }
.btn-muted { background: #eef1f4; color: var(--text); }
.btn-sm { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.btn-link { background: transparent; border: 0; color: var(--primary); padding: 4px; min-height: auto; }

.alert { padding: 13px 16px; border-radius: 9px; margin-bottom: 18px; border: 1px solid transparent; }
.alert-success { color: #116547; background: #e7f8f1; border-color: #b5ead8; }
.alert-danger { color: #8f1f32; background: #fdecef; border-color: #f6c5ce; }
.alert-warning { color: #80500b; background: #fff6e8; border-color: #f7d8a8; }

.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid rgba(0,0,0,.09); vertical-align: middle; text-align: left; }
.table th { background: #f6f6f6; text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 700; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-success { background: #e7f8f1; color: #116547; }
.badge-muted { background: #eef1f4; color: #5f6f7d; }
.filters { display: grid; grid-template-columns: minmax(240px, 1fr) 180px 180px auto; gap: 12px; align-items: end; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 18px; }
.pagination a, .pagination span { min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; border: 1px solid var(--border); background: white; }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }
.empty-state { padding: 42px 20px; text-align: center; color: var(--muted); }
.inline-form { display: inline; }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.detail-item { padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: #fbfcfd; }
.detail-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.detail-value { white-space: pre-wrap; overflow-wrap: anywhere; }

.module-permissions { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) repeat(4, 100px) auto; gap: 12px; align-items: end; }
.mobile-menu-button { display: none; }

@media (max-width: 1100px) {
    .login-page { grid-template-columns: 1fr; }
    .login-visual { display: none; }
    .installer-page { grid-template-columns: 1fr; }
    .metric-grid { grid-template-columns: 1fr; }
    .option-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .module-permissions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 850px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -280px; width: 264px; z-index: 50; transition: left .2s; }
    body.sidebar-open .sidebar { left: 0; }
    .mobile-menu-button { display: inline-flex; }
    .topbar { padding: 0 18px; }
    .content { padding: 18px; }
    .filters { grid-template-columns: 1fr; }
    .col-9, .col-8, .col-6, .col-4, .col-3, .col-2 { grid-column: span 12; }
    .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .login-page { padding: 0; }
    .login-panel { padding: 28px 20px; }
    .login-logo { margin-bottom: 44px; }
    .login-title { font-size: 34px; }
    .installer-grid { grid-template-columns: 1fr; }
    .installer-grid .installer-col-2 { grid-column: span 1; }
    .option-grid { grid-template-columns: 1fr; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .user-meta { display: none; }
}
