:root {
    --bg: #f3f6f7;
    --panel: #ffffff;
    --panel-alt: #edf3f4;
    --primary: #1e2b2c;
    --primary-dark: #0f1d20;
    --gold: #d9a928;
    --gold-soft: #fff1c7;
    --success: #2e8b57;
    --danger: #d9534f;
    --text: #1d2b2f;
    --muted: #697a7d;
    --line: #dfe7e8;
    --shadow: 0 18px 45px rgba(12, 27, 31, 0.1);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(217, 169, 40, 0.08), transparent 28%),
        linear-gradient(180deg, #f8f9fa 0%, #eef3f4 100%);
    color: var(--text);
}

body {
    line-height: 1.6;
}

img {
    max-width: 100%;
    display: block;
}

a {
    text-decoration: none;
    color: inherit;
}

button, input, select, textarea {
    font: inherit;
}

.admin-app {
    min-height: 100vh;
}

.admin-topbar {
    background: linear-gradient(180deg, #1e2b2c 0%, #0f1d20 100%);
    color: #ecf3f3;
    padding: 20px 28px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    position: sticky;
    top: 0;
    z-index: 50;
}

.admin-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: nowrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--gold), #f5d36c);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-weight: 800;
    box-shadow: 0 10px 18px rgba(217,169,40,0.25);
}

.brand h2 {
    font-size: 0.92rem;
    margin: 0;
    letter-spacing: 0.04em;
}

.brand span {
    font-size: 0.62rem;
    color: #d4dfe0;
    display: block;
    margin-top: 2px;
}

.side-menu {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
    flex: 1 1 auto;
    flex-wrap: nowrap;
    min-width: 0;
    white-space: nowrap;
}

.side-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 6px;
    border-radius: 7px;
    color: #dfeae9;
    transition: 0.2s ease;
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
}

.side-link:hover,
.side-link.active {
    background: rgba(217, 169, 40, 0.12);
    color: #fff6d4;
    border-bottom: 2px solid var(--gold);
    border-left: none;
    padding-bottom: 8px;
}

.content {
    padding: 28px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.eyebrow {
    margin: 0 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.topbar h1 {
    font-size: clamp(1.8rem, 2vw, 2.4rem);
    margin: 0;
    color: var(--primary);
}

.btn {
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--gold), #eec75d);
    color: var(--primary-dark);
    box-shadow: 0 10px 18px rgba(217,169,40,0.22);
}

.btn-secondary {
    background: var(--primary);
    color: #f9fbfb;
}

.btn-danger {
    background: #fbe7e6;
    color: var(--danger);
    padding: 8px 11px;
    font-size: 0.82rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-grid;
    place-items: center;
}

.btn-icon i {
    font-size: 1rem;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.btn-edit {
    background: #edf5ff;
    color: #1f5aa7;
    padding: 8px 11px;
    font-size: 0.82rem;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.stat-card,
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.stat-card {
    padding: 20px 18px;
    background: linear-gradient(180deg, #ffffff 0%, #f9fbfb 100%);
}

.stat-label {
    font-size: 0.76rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.stat-number {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
}

.empty-state {
    padding: 34px 16px;
    color: var(--muted);
    text-align: center;
    font-style: italic;
}

.global-loading {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(15, 29, 32, .42);
    color: #fff;
    font-weight: 700;
}

.global-loading[hidden] {
    display: none;
}

.swal2-container {
    z-index: 3000 !important;
}

.spinner,
.button-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, .45);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.button-spinner {
    display: none;
    width: 14px;
    height: 14px;
    margin-right: 8px;
    vertical-align: -2px;
}

.btn.is-loading .button-spinner {
    display: inline-block;
}

.table-skeleton {
    height: 22px;
    border-radius: 6px;
    background: linear-gradient(90deg, #edf1f1 25%, #f8fafa 50%, #edf1f1 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

.card {
    padding: 22px;
    margin-bottom: 24px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.card-header h2,
.card-header h3 {
    margin: 0;
    color: var(--primary);
}

.table-toolbar {
    align-items: end;
}

.table-count {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: .8rem;
}

.table-search {
    display: grid;
    gap: 5px;
    min-width: min(320px, 100%);
    color: var(--muted);
    font-size: .75rem;
    font-weight: 700;
}

.table-search input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: #fff;
}

.table-search input:focus {
    outline: 3px solid rgba(217, 169, 40, .2);
    border-color: var(--gold);
}

.table-wrap {
    overflow-x: auto;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px 0 2px;
}

.pagination-pages {
    display: flex;
    align-items: center;
    gap: 5px;
}

.pagination button {
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 7px 10px;
    background: #fff;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
}

.pagination button:hover:not(:disabled),
.pagination-number.active {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--primary-dark);
}

.pagination button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th, td {
    text-align: left;
    padding: 14px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

.description-cell {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th {
    background: #f7f9f9;
    color: var(--primary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

tbody tr:hover {
    background: #fbfcfc;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--gold-soft);
    color: #7a5b09;
    text-transform: capitalize;
}

.empty-box {
    padding: 24px;
    text-align: center;
    color: var(--muted);
    background: #fafbfb;
    border: 1px dashed var(--line);
    border-radius: 12px;
}

.recent-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 12px;
}

.recent-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid var(--line);
}

.recent-list strong {
    display: block;
    color: var(--primary);
}

.recent-list span {
    color: var(--muted);
    font-size: 0.8rem;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 21, 22, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 1055;
}

.modal.open {
    display: flex;
    opacity: 1;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-panel {
    width: min(760px, 100%);
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.20);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.login-panel {
    width: min(440px, 100%);
}

.login-error {
    min-height: 1.4em;
    margin: 12px 0 0;
    color: var(--danger);
    font-size: 0.85rem;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
    background: #f8f9f9;
}

.modal-head h3 {
    margin: 0;
    color: var(--primary);
}

.close-btn {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    color: var(--muted);
    cursor: pointer;
}

.modal-body {
    padding: 22px;
    overflow-y: auto;
}

#recordForm {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-group {
    display: grid;
    gap: 8px;
}

.inline-field {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.inline-field select {
    flex: 1;
    min-width: 0;
}

.photo-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
    margin-top: 4px;
}

.photo-preview-item {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f8f9f9;
}

.photo-preview-item img {
    width: 88px;
    height: 88px;
    object-fit: cover;
    border-radius: 8px;
    background: #e9eeee;
}

.photo-preview-info {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.photo-preview-info label {
    font-size: 0.76rem;
}

.file-help {
    color: var(--muted);
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.repeat-fields {
    display: grid;
    gap: 10px;
}

.repeat-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) auto;
    gap: 8px;
    align-items: center;
}

.repeat-add {
    margin-top: 10px;
}

.form-group.full {
    grid-column: 1 / -1;
}

label {
    font-size: 0.82rem;
    color: var(--primary);
    font-weight: 600;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(217,169,40,0.22);
    border-color: var(--gold);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.rich-text-editor {
    min-height: 180px;
    border: 1px solid var(--line);
    border-radius: 0 0 10px 10px;
    background: #fff;
}

.rich-text-editor .ql-editor {
    min-height: 140px;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
}

.ql-toolbar.ql-snow {
    border: 1px solid var(--line);
    border-radius: 10px 10px 0 0;
    background: #f8f9f9;
}

.ql-container.ql-snow {
    border: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 22px;
}

@media (max-width: 980px) {
    .admin-topbar-inner {
        justify-content: center;
    }

    .side-menu {
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .content {
        padding: 18px;
    }
}

@media (max-width: 640px) {
    .table-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .table-search {
        min-width: 0;
    }

    .modal {
        padding: 12px;
    }

    .modal-panel {
        max-height: calc(100vh - 24px);
    }

    .modal-body {
        padding: 16px;
    }

    #recordForm {
        grid-template-columns: 1fr;
    }

    .inline-field {
        flex-direction: column;
    }

    .photo-preview-item {
        grid-template-columns: 72px minmax(0, 1fr);
    }

    .photo-preview-item img {
        width: 72px;
        height: 72px;
    }

    .repeat-row {
        grid-template-columns: 1fr;
    }

    .pagination {
        gap: 6px;
    }

    .pagination-arrow {
        font-size: 0;
    }

    .pagination-arrow::after {
        font-size: 0.82rem;
        content: '‹';
    }

    .pagination-arrow:not(:disabled)::after {
        content: '›';
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-topbar {
        padding-left: 16px;
        padding-right: 16px;
    }

    .side-link {
        padding: 9px 10px;
        font-size: 0.8rem;
    }
}
