:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #dadfe5;
    --border-strong: #b9c2cb;
    --text: #1c2530;
    --muted: #6b7682;
    --accent: #2f6fb5;
    --accent-hover: #245a96;
    --shadow: 0 6px 20px rgba(20, 30, 50, 0.08);
    --radius: 6px;
    --radius-sm: 4px;
    --success-bg: #e8f5ec;
    --success-text: #2a6b41;
    --error-bg: #fdecec;
    --error-text: #9c2e2e;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    color: var(--text);
    font-family: Georgia, "Times New Roman", serif;
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ---------- LOGIN ---------- */

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
}

.login-shell {
    width: 100%;
    max-width: 380px;
}

.login-panel {
    display: grid;
    gap: 18px;
    padding: 32px 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-panel h1 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 400;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    text-align: center;
    color: var(--text);
}

.login-form {
    display: grid;
    gap: 12px;
}

.login-button {
    margin-top: 6px;
}

/* ---------- ADMIN ---------- */

.admin-body {
    min-height: 100vh;
    padding: 24px 32px 60px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin: 0 0 28px;
    padding: 0 4px;
}

.topbar h1 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text);
}

.topbar-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.topbar-user {
    color: var(--muted);
    font-size: 0.85rem;
}

.admin-layout {
    display: grid;
    gap: 32px;
    width: 100%;
    max-width: 880px;
    margin: 0 auto;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.form-card {
    padding: 26px 30px;
}

/* ---------- FORM ---------- */

.material-form {
    display: grid;
    gap: 14px;
}

.field-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
}

.text-input,
select,
input[type="file"] {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    color: var(--text);
    font: inherit;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.text-input:focus,
select:focus,
input[type="file"]:focus {
    outline: 2px solid rgba(47, 111, 181, 0.25);
    outline-offset: 1px;
    border-color: var(--accent);
}

.text-area {
    min-height: 80px;
    resize: vertical;
}

.inline-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    cursor: pointer;
}

.field-hint {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-style: italic;
}

.flash,
.form-error {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.flash-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.flash-error,
.form-error {
    background: var(--error-bg);
    color: var(--error-text);
}

/* ---------- PERMISSIONS ACCORDION ---------- */

.permissions-block {
    margin-top: 6px;
}

.permissions-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 22px;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    font-size: 0.92rem;
    cursor: pointer;
}

.permissions-toggle:hover {
    background: #f1f4f8;
}

.permissions-toggle::after {
    content: "▾";
    color: var(--muted);
    font-size: 0.75rem;
    transition: transform 0.15s ease;
}

.permissions-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

.permissions-hint {
    margin: 10px 0 0;
    font-weight: 700;
    color: var(--text);
    font-size: 0.9rem;
}

.chip-grid {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 6px 24px;
    margin-top: 12px;
    padding: 14px 4px 4px;
    border-top: 1px dashed var(--border);
}

.chip-grid.is-open {
    display: grid;
}

.chip-grid[hidden] {
    display: none;
}

.file-field[hidden] {
    display: none;
}

.chip-option {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.88rem;
    cursor: pointer;
}

.chip-option input[type="checkbox"] {
    accent-color: var(--accent);
}

/* ---------- ACTIONS ---------- */

.form-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.primary-button,
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 24px;
    border: 0;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 700;
    font-size: 0.92rem;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease;
}

.primary-button {
    color: #fff;
    background: var(--accent);
}

.primary-button:hover {
    background: var(--accent-hover);
}

.secondary-button {
    color: var(--text);
    background: #e6ebf1;
}

.secondary-button:hover {
    background: #d7dee6;
}

/* ---------- SUMMARY: TABS + TABLE ---------- */

.summary-card {
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.summary-header {
    display: grid;
    gap: 14px;
    margin-bottom: 0;
}

.summary-header h2 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 400;
    color: var(--text);
}

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 8px 16px;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-bottom: 0;
    border-top-left-radius: var(--radius-sm);
    border-top-right-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.85rem;
    text-decoration: none;
    cursor: pointer;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--text);
    background: #fff;
    border-color: var(--border);
    margin-bottom: -1px;
}

.table-wrapper {
    overflow-x: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-top: 0;
    border-bottom-left-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
}

.table-wrapper[hidden] {
    display: none;
}

.materials-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.materials-table th,
.materials-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.materials-table th {
    background: #fafbfc;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 700;
}

.materials-table tbody tr:last-child td {
    border-bottom: 0;
}

.materials-table tbody tr:hover {
    background: #fafbfc;
}

.status-cell {
    color: var(--accent);
    font-weight: 700;
    text-align: center;
}

.actions-cell {
    white-space: nowrap;
    text-align: right;
}

.icon-button,
.icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: 0 1px;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.icon-button:hover,
.icon-link:hover {
    color: var(--accent);
    background: #f1f4f8;
}

.icon-button svg,
.icon-link svg {
    width: 16px;
    height: 16px;
}

.icon-separator {
    color: var(--border-strong);
    user-select: none;
    font-size: 0.85rem;
}

.inline-form {
    display: inline;
    margin: 0;
}

.empty-state {
    padding: 28px 16px;
    color: var(--muted);
    text-align: center;
    font-size: 0.92rem;
    background: #fff;
    border: 1px solid var(--border);
    border-top: 0;
    border-bottom-left-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
}

@media (max-width: 720px) {
    .admin-body {
        padding: 16px;
    }

    .form-card {
        padding: 18px;
    }

    .topbar {
        flex-wrap: wrap;
    }
}
