:root {
    color-scheme: light;
    --bg: #f6f7f4;
    --surface: #ffffff;
    --surface-strong: #f9faf7;
    --text: #17201c;
    --muted: #66736c;
    --border: #d9dfd8;
    --accent: #b33b2e;
    --accent-dark: #852b22;
    --rail: #27312d;
    --success: #2f7d50;
    --warning: #b7791f;
    --danger: #a83232;
    --focus: #2f6fed;
    --shadow: 0 10px 30px rgba(23, 32, 28, 0.08);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121614;
    --surface: #1b211e;
    --surface-strong: #222a26;
    --text: #eef3ef;
    --muted: #a7b3ac;
    --border: #39443f;
    --accent: #df6a5b;
    --accent-dark: #ff9b8e;
    --rail: #1b211f;
    --success: #4fa46f;
    --warning: #d39a34;
    --danger: #d45b5b;
    --focus: #80aaff;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent-dark);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: center;
    padding: 14px 28px;
    background: var(--rail);
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.brand {
    color: white;
    font-weight: 800;
    text-decoration: none;
    font-size: 18px;
    letter-spacing: 0;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.nav a,
.theme-toggle,
.user-pill {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    color: white;
    font-size: 14px;
    line-height: 1;
    padding: 8px 10px;
    text-decoration: none;
}

.nav a:hover,
.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.theme-toggle {
    background: transparent;
    cursor: pointer;
    font: inherit;
}

.user-pill {
    color: #ecf1ed;
    background: rgba(255, 255, 255, 0.08);
}

.container {
    width: min(1160px, calc(100% - 32px));
    margin: 28px auto 48px;
}

.page-heading,
.detail-header {
    margin-bottom: 20px;
}

.page-heading h1,
.detail-header h1 {
    margin-bottom: 6px;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
}

h1,
h2 {
    margin: 0 0 10px;
    line-height: 1.15;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(28px, 4vw, 42px);
}

h2 {
    font-size: 22px;
}

p {
    margin: 0 0 14px;
    color: var(--muted);
}

.company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 16px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat-box,
.company-card,
.panel,
.empty-state,
.search-form,
.admin-company-item,
.admin-user-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stat-box {
    display: grid;
    gap: 4px;
    padding: 16px;
}

.stat-box strong {
    font-size: 30px;
    line-height: 1;
}

.stat-box span {
    color: var(--muted);
    font-size: 14px;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.inline-check {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 8px;
}

.inline-check input {
    width: auto;
}

.search-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(140px, 180px)) auto auto;
    align-items: end;
    gap: 12px;
    margin: 0 0 22px;
    padding: 14px;
}

.search-label {
    min-width: 0;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 24px 0 0;
}

.company-card,
.panel,
.empty-state {
    padding: 18px;
}

.company-card {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.company-card h2 a,
.admin-company-name {
    color: var(--text);
    text-decoration: none;
}

.company-card h2 a:hover,
.admin-company-name:hover {
    color: var(--accent-dark);
    text-decoration: underline;
}

.card-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.card-delete-form {
    display: grid;
    gap: 8px;
    margin-top: auto;
    padding-top: 14px;
}

.short-name {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
}

.company-logo {
    width: 100%;
    height: 118px;
    object-fit: contain;
    margin-bottom: 14px;
    padding: 10px;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.company-logo.preview {
    width: 180px;
    height: 120px;
}

.company-logo.detail {
    max-width: 260px;
    height: 160px;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    min-height: 24px;
    font-size: 12px;
    font-weight: 800;
    color: white;
    background: var(--rail);
}

.status-pending {
    background: var(--warning);
}

.status-active {
    background: var(--success);
}

.status-inactive {
    background: #66736c;
}

.status-dissolved,
.status-rejected {
    background: var(--danger);
}

.meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 18px 0 0;
}

.meta.large {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

dd {
    margin: 0;
    font-weight: 750;
}

.messages {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.message {
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.message.success {
    border-color: var(--success);
}

.message.error {
    border-color: var(--danger);
}

.form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--text);
    font-size: 14px;
    font-weight: 750;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    background: var(--surface-strong);
    color: var(--text);
    font: inherit;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible,
.button:focus-visible,
a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus), transparent 65%);
    outline-offset: 2px;
}

textarea {
    resize: vertical;
}

.field-hint {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.checkbox-list {
    display: grid;
    gap: 6px;
    max-height: 240px;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-strong);
}

.checkbox-row {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    font-weight: 650;
}

.checkbox-row:hover {
    background: var(--surface);
}

.checkbox-row input {
    width: auto;
    flex: 0 0 auto;
}

.checkbox-row.is-disabled {
    color: var(--muted);
    cursor: not-allowed;
}

.actions,
.admin-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 10px 14px;
    background: var(--accent);
    color: white;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.button:hover {
    filter: brightness(0.96);
}

.button.secondary {
    background: transparent;
    color: var(--accent-dark);
}

.small {
    padding: 7px 10px;
    font-size: 14px;
}

.danger {
    background: var(--danger);
    border-color: var(--danger);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
}

.admin-company-list,
.admin-user-list {
    display: grid;
    gap: 12px;
}

.admin-company-item {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(320px, 1.15fr);
    gap: 16px;
    align-items: start;
    padding: 14px;
    box-shadow: none;
}

.admin-company-name {
    display: inline-block;
    margin-bottom: 8px;
    font-size: 18px;
    font-weight: 800;
}

.admin-company-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.admin-actions {
    align-items: stretch;
    flex-direction: column;
}

.admin-actions form {
    display: grid;
    grid-template-columns: minmax(120px, 0.7fr) minmax(180px, 1fr) auto;
    gap: 8px;
    width: 100%;
}

.admin-actions form[action*="reject"],
.admin-actions form[action*="delete"] {
    grid-template-columns: minmax(180px, 1fr) auto;
}

.admin-user-item {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 14px;
    box-shadow: none;
}

.admin-user-role-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.muted {
    color: var(--muted);
    font-size: 14px;
}

.timeline {
    display: grid;
    gap: 14px;
    margin: 0;
    padding-left: 20px;
}

.timeline li {
    padding-left: 4px;
}

.timeline span,
.timeline small {
    display: block;
}

.timeline small {
    color: var(--muted);
}

@media (max-width: 920px) {
    .search-form {
        grid-template-columns: 1fr 1fr;
    }

    .admin-company-item {
        grid-template-columns: 1fr;
    }

    .admin-actions form,
    .admin-actions form[action*="reject"],
    .admin-actions form[action*="delete"] {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    body {
        line-height: 1.45;
    }

    .site-header,
    .detail-header {
        flex-direction: column;
    }

    .site-header {
        align-items: flex-start;
        gap: 12px;
        padding: 12px;
    }

    .brand {
        font-size: 17px;
        line-height: 1.2;
    }

    .nav {
        width: 100%;
        gap: 8px;
        justify-content: flex-start;
    }

    .nav a,
    .theme-toggle,
    .user-pill {
        font-size: 13px;
        padding: 7px 8px;
    }

    .container {
        width: min(100% - 20px, 1160px);
        margin: 18px auto;
    }

    .page-heading,
    .detail-header {
        margin-bottom: 16px;
    }

    .company-grid,
    .search-form {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .company-card,
    .panel,
    .empty-state,
    .search-form {
        padding: 14px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .meta {
        grid-template-columns: 1fr;
    }

    .section-title-row,
    .actions,
    .admin-actions,
    .admin-user-role-form {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .actions > *,
    .admin-actions > *,
    .admin-actions form,
    .admin-user-role-form > *,
    .card-delete-form button {
        width: 100%;
    }

    button,
    .button {
        min-height: 42px;
        width: 100%;
        text-align: center;
    }

    .small {
        min-height: 38px;
    }

    input,
    textarea,
    select {
        min-height: 42px;
        font-size: 16px;
    }

    .admin-company-item,
    .admin-user-item {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
    }

    .company-logo {
        height: 96px;
    }

    .company-logo.detail,
    .company-logo.preview {
        width: 100%;
        max-width: none;
        height: 130px;
    }

    .pagination {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nav a,
    .theme-toggle,
    .user-pill {
        display: flex;
        justify-content: center;
        min-width: 0;
        text-align: center;
    }

    .user-pill {
        grid-column: 1 / -1;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .card-row,
    .admin-company-meta {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }

    .short-name,
    .admin-company-meta span {
        overflow-wrap: anywhere;
    }

    .timeline {
        padding-left: 18px;
    }
}
