/* ==========================================================================
   OTK Rijeka CRM — Admin Panel Stylesheet
   ========================================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
    --color-primary: #005ba1;
    --color-primary-hover: #004a83;
    --color-primary-light: #d6eaf8;

    --color-success: #22c55e;
    --color-success-hover: #16a34a;
    --color-success-light: #dcfce7;

    --color-warning: #f59e0b;
    --color-warning-hover: #d97706;
    --color-warning-light: #fef3c7;

    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-danger-light: #fee2e2;

    --color-sidebar: #005ba1;
    --color-sidebar-hover: #2b77b1;
    --color-sidebar-text: #ffffff;
    --color-sidebar-active: #ffffff;

    --color-bg: #f1f5f9;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;

    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-light: #94a3b8;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);

    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;

    --sidebar-width: 250px;
    --header-height: 60px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
        "Segoe UI Emoji";
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

    --transition: 150ms ease;

    --fs-base: 17px;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--fs-base);
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-text);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p {
    margin-bottom: 0.75rem;
}

small {
    font-size: 0.8125rem;
}

code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

/* ---------- Layout: Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-sidebar);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.sidebar-brand a {
    display: flex;
    align-items: center;
}

.sidebar-brand-logo {
    width: 115px;
    height: 72px;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    list-style: none;
}

.sidebar-section-title {
    display: block;
    padding: 16px 20px 6px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.45);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--color-sidebar-text);
    font-size: var(--fs-sidebar, 0.9rem);
    font-weight: 450;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background var(--transition), color var(--transition),
        border-color var(--transition);
}

.sidebar-link:hover {
    background: var(--color-sidebar-hover);
    color: var(--color-sidebar-active);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--color-sidebar-hover);
    color: var(--color-sidebar-active);
    border-left-color: #ffffff;
    font-weight: 500;
}

.sidebar-link-icon {
    width: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-link-icon svg {
    width: 18px;
    height: 18px;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
}

/* ---------- Layout: Header ---------- */
.header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 24px;
    z-index: 90;
    transition: left var(--transition);
}

.header-left {
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.header-user strong {
    color: var(--color-text);
    font-weight: 500;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    margin-right: auto;
    background: var(--color-primary);
    border: none;
    font-size: 1.35rem;
    color: #ffffff;
    cursor: pointer;
    padding: 7px 14px;
    border-radius: var(--radius);
    line-height: 1;
}

.sidebar-toggle span {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sidebar-toggle:hover {
    background: var(--color-primary-hover);
}

/* ---------- Layout: Main Content ---------- */
.main-content {
    margin-left: var(--sidebar-width);
    padding: calc(var(--header-height) + 24px) 24px 24px 24px;
    min-height: 100vh;
    transition: margin-left var(--transition);
}

.content-wrapper {
    padding: 24px;
}

/* ---------- Page Header ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h2,
.card-header h3,
.card-header h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- Stat Cards ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.stat-card-content {
    flex: 1;
    min-width: 0;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-text);
}

.stat-card-label {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.stat-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-card-icon.blue   { background: var(--color-primary-light); color: var(--color-primary); }
.stat-card-icon.green  { background: var(--color-success-light); color: var(--color-success); }
.stat-card-icon.amber  { background: var(--color-warning-light); color: var(--color-warning); }
.stat-card-icon.red    { background: var(--color-danger-light);  color: var(--color-danger); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition),
        color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
}

.btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--color-primary);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    color: #ffffff;
    text-decoration: none;
}

.btn-success {
    background: var(--color-success);
    color: #ffffff;
}

.btn-success:hover {
    background: var(--color-success-hover);
    color: #ffffff;
    text-decoration: none;
}

.btn-danger {
    background: var(--color-danger);
    color: #ffffff;
}

.btn-danger:hover {
    background: var(--color-danger-hover);
    color: #ffffff;
    text-decoration: none;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
    color: var(--color-text);
    text-decoration: none;
}

.btn-warning {
    background: var(--color-warning);
    color: #ffffff;
}

.btn-warning:hover {
    background: var(--color-warning-hover);
    color: #ffffff;
    text-decoration: none;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8125rem;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: var(--radius);
}

.btn-icon.btn-sm {
    width: 28px;
    height: 28px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-primary);
    padding: 0;
    font-weight: 400;
}

.btn-link:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

/* ---------- Tables ---------- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-table, 0.875rem);
}

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

.table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
    background: var(--color-bg);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

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

.table-striped tbody tr:nth-child(even) {
    background: rgba(241, 245, 249, 0.5);
}

.table-hover tbody tr:hover {
    background: rgba(59, 130, 246, 0.04);
}

.table td .actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* ---------- Forms ---------- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 4px;
}

.form-label .required {
    color: var(--color-danger);
    margin-left: 2px;
}

.form-control {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-control::placeholder {
    color: var(--color-text-light);
}

.form-control:disabled,
.form-control[readonly] {
    background: var(--color-bg);
    opacity: 0.7;
    cursor: not-allowed;
}

.form-control.is-invalid {
    border-color: var(--color-danger);
}

.form-control.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

select.form-control {
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.form-error {
    font-size: 0.75rem;
    color: var(--color-danger);
    margin-top: 4px;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 8px;
    padding-top: 8px;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.6;
    border-radius: 9999px;
    white-space: nowrap;
    background: var(--color-bg);
    color: var(--color-text-muted);
}

.badge-active,
.badge-paid {
    background: var(--color-success-light);
    color: var(--color-success-hover);
}

.badge-inactive,
.badge-expired {
    background: var(--color-danger-light);
    color: var(--color-danger-hover);
}

.badge-pending {
    background: var(--color-warning-light);
    color: var(--color-warning-hover);
}

.badge-paused {
    background: #f1f5f9;
    color: #64748b;
}

.badge-primary {
    background: var(--color-primary-light);
    color: var(--color-primary-hover);
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
    padding: 0;
    margin: 20px 0 0;
}

.page-item {
    display: inline-flex;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: 0.8125rem;
    font-weight: 450;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.page-link:hover {
    background: var(--color-bg);
    color: var(--color-text);
    text-decoration: none;
}

.page-item.active .page-link,
.page-link.active {
    background: var(--color-primary);
    color: #ffffff;
    border-color: var(--color-primary);
    font-weight: 600;
}

.page-link.active:hover {
    background: var(--color-primary-hover);
    color: #ffffff;
}

.page-item.disabled .page-link {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination-info {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-left: auto;
}

/* ---------- Alerts / Flash Messages ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--color-success-light);
    color: #166534;
    border-color: #bbf7d0;
}

.alert-error {
    background: var(--color-danger-light);
    color: #991b1b;
    border-color: #fecaca;
}

.alert-warning {
    background: var(--color-warning-light);
    color: #92400e;
    border-color: #fde68a;
}

.alert-info {
    background: var(--color-primary-light);
    color: #1e40af;
    border-color: #bfdbfe;
}

.alert-dismiss {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.5;
    padding: 0 4px;
    line-height: 1;
}

.alert-dismiss:hover {
    opacity: 1;
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 380px;
}

.toast-message {
    pointer-events: auto;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--color-sidebar);
    color: #ffffff;
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toast-in 300ms ease-out, toast-out 300ms ease-in forwards;
    animation-delay: 0s, 3.5s;
}

.toast-message.toast-success {
    border-left: 4px solid var(--color-success);
}

.toast-message.toast-error {
    border-left: 4px solid var(--color-danger);
}

.toast-message.toast-warning {
    border-left: 4px solid var(--color-warning);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    animation: fade-in 150ms ease;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modal-in 200ms ease;
}

.modal-lg {
    max-width: 640px;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3,
.modal-header h4 {
    margin: 0;
    font-size: 1.05rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(-8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- Filters Bar ---------- */
.filters-bar {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    padding: 14px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.filters-bar .form-group,
.filters-bar .filter-group {
    margin-bottom: 0;
    min-width: 160px;
}

.filters-bar .form-label {
    font-size: 0.75rem;
    margin-bottom: 3px;
}

.filters-bar .form-control {
    padding: 6px 10px;
    font-size: 0.8125rem;
}

.filters-bar .btn {
    align-self: flex-end;
}

/* ---------- Thumbnails & Images ---------- */
.thumbnail {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 1px solid var(--color-border);
    flex-shrink: 0;
}

.thumbnail-lg {
    width: 56px;
    height: 56px;
}

.image-preview {
    max-width: 320px;
    max-height: 240px;
    border-radius: var(--radius-lg);
    object-fit: cover;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.image-preview-lg {
    max-width: 480px;
    max-height: 360px;
}

/* ---------- Dropdown ---------- */
.dropdown {
    position: relative;
    display: inline-flex;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 200;
    min-width: 160px;
    padding: 4px 0;
    margin-top: 4px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    display: none;
    animation: fade-in 100ms ease;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 14px;
    font-size: 0.8125rem;
    color: var(--color-text);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition);
}

.dropdown-item:hover {
    background: var(--color-bg);
    text-decoration: none;
}

.dropdown-item.danger {
    color: var(--color-danger);
}

.dropdown-item.danger:hover {
    background: var(--color-danger-light);
}

.dropdown-divider {
    height: 1px;
    margin: 4px 0;
    background: var(--color-border);
}

/* ---------- Empty State ---------- */
.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--color-text-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--color-text);
}

.empty-state-text {
    font-size: 0.875rem;
    margin-bottom: 16px;
}

/* ---------- Loading Spinner ---------- */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

.spinner-center {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Search Select (AJAX member selector) ---------- */
.search-select {
    position: relative;
}

.search-select .form-control {
    padding-right: 32px;
}

.search-select-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-light);
    pointer-events: none;
    font-size: 0.875rem;
}

.search-select-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 300;
    margin-top: 2px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow-y: auto;
    display: none;
}

.search-select-results.show {
    display: block;
}

.search-select-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background var(--transition);
}

.search-select-item:hover,
.search-select-item.highlighted {
    background: var(--color-primary-light);
}

.search-select-item-name {
    font-weight: 500;
}

.search-select-item-meta {
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.search-select-empty {
    padding: 12px;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.search-select-loading {
    padding: 12px;
    text-align: center;
}

/* ---------- Login Page ---------- */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #005ba1;
    padding: 48px 20px;
    width: 100%;
}

.login-page-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.login-page-brand img {
    width: 160px;
    height: 100px;
    object-fit: contain;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 460px;
    padding: 44px 40px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo img {
    height: 48px;
    margin-bottom: 12px;
}

.login-logo h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-text);
}

.login-logo p {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0;
}

.login-card .form-group {
    margin-bottom: 18px;
}

.login-card .btn-primary {
    width: 100%;
    padding: 10px 16px;
    font-size: 0.9375rem;
}

/* ---------- Minimal Layout & Error Page ---------- */
.minimal-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #005ba1;
    padding: 0;
}

.minimal-container {
    text-align: center;
    max-width: none;
    width: 100%;
}

.error-page {
    text-align: center;
    padding: 48px 24px;
}

.error-page-code {
    font-size: 5rem;
    font-weight: 800;
    color: var(--color-primary);
    line-height: 1;
    margin-bottom: 12px;
}

.error-page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.error-page-text {
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

/* ---------- Tabs (Member detail sections) ---------- */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--color-border);
    gap: 0;
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color var(--transition), border-color var(--transition);
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

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

.tab-link.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ---------- Detail Sections (Member page) ---------- */
.detail-section {
    margin-bottom: 24px;
}

.detail-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.detail-section-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px 24px;
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-field-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.detail-field-value {
    font-size: 0.9375rem;
    color: var(--color-text);
}

/* ---------- Audit Log ---------- */
.audit-log {
    list-style: none;
    padding: 0;
}

.audit-log-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--color-border);
}

.audit-log-item:last-child {
    border-bottom: none;
}

.audit-log-time {
    color: var(--color-text-muted);
    white-space: nowrap;
    min-width: 130px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.audit-log-action {
    font-weight: 500;
}

.audit-log-user {
    color: var(--color-text-muted);
    margin-left: auto;
    white-space: nowrap;
}

/* ---------- Audit List (detail pages) ---------- */
.audit-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.audit-item {
    padding: 12px 20px;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.875rem;
}

.audit-item:last-child {
    border-bottom: none;
}

.audit-meta {
    display: flex;
    gap: 12px;
    margin-bottom: 2px;
}

.audit-user {
    font-weight: 600;
    color: var(--color-text);
}

.audit-time {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.audit-action {
    color: var(--color-text-muted);
}

/* ---------- Utility Classes ---------- */
.text-muted    { color: var(--color-text-muted) !important; }
.text-success  { color: var(--color-success) !important; }
.text-danger   { color: var(--color-danger) !important; }
.text-warning  { color: var(--color-warning) !important; }
.text-primary  { color: var(--color-primary) !important; }
.text-center   { text-align: center !important; }
.text-right    { text-align: right !important; }
.text-left     { text-align: left !important; }
.text-nowrap   { white-space: nowrap !important; }
.text-sm       { font-size: 0.8125rem !important; }
.text-xs       { font-size: 0.75rem !important; }

.fw-normal     { font-weight: 400 !important; }
.fw-medium     { font-weight: 500 !important; }
.fw-semibold   { font-weight: 600 !important; }
.fw-bold       { font-weight: 700 !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 4px !important; }
.mt-2 { margin-top: 8px !important; }
.mt-3 { margin-top: 16px !important; }
.mt-4 { margin-top: 24px !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 4px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-3 { margin-bottom: 16px !important; }
.mb-4 { margin-bottom: 24px !important; }

.ml-auto { margin-left: auto !important; }
.mr-auto { margin-right: auto !important; }

.p-0 { padding: 0 !important; }
.p-1 { padding: 4px !important; }
.p-2 { padding: 8px !important; }
.p-3 { padding: 16px !important; }
.p-4 { padding: 24px !important; }

.d-flex          { display: flex !important; }
.d-inline-flex   { display: inline-flex !important; }
.d-block         { display: block !important; }
.d-inline-block  { display: inline-block !important; }
.d-none          { display: none !important; }

.flex-column     { flex-direction: column !important; }
.flex-wrap       { flex-wrap: wrap !important; }
.flex-1          { flex: 1 !important; }

.justify-between { justify-content: space-between !important; }
.justify-center  { justify-content: center !important; }
.justify-end     { justify-content: flex-end !important; }

.align-center    { align-items: center !important; }
.align-start     { align-items: flex-start !important; }
.align-end       { align-items: flex-end !important; }

.gap-1 { gap: 4px !important; }
.gap-2 { gap: 8px !important; }
.gap-3 { gap: 16px !important; }
.gap-4 { gap: 24px !important; }

.w-100 { width: 100% !important; }

.rounded { border-radius: var(--radius) !important; }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Responsive: < 1024px — Collapsible sidebar ---------- */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .header {
        left: 0;
        background: #005ba1;
        border-bottom-color: rgba(255, 255, 255, 0.15);
    }

    .header-user {
        color: rgba(255, 255, 255, 0.85);
    }

    .header-user strong {
        color: #ffffff;
    }

    .header-right .badge {
        background: rgba(255, 255, 255, 0.15);
        color: #ffffff;
    }

    .header-right .btn-secondary {
        background: rgba(255, 255, 255, 0.15);
        color: #ffffff;
        border-color: rgba(255, 255, 255, 0.25);
    }

    .header-right .btn-secondary:hover {
        background: rgba(255, 255, 255, 0.25);
        color: #ffffff;
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: flex;
        background: rgba(255, 255, 255, 0.15);
        color: #ffffff;
    }

    .sidebar-toggle:hover {
        background: rgba(255, 255, 255, 0.25);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 99;
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

/* ---------- Responsive: < 768px — Compact mobile ---------- */
@media (max-width: 768px) {
    html {
        font-size: 16px;
    }

    .main-content {
        padding-left: 16px;
        padding-right: 16px;
        padding-bottom: 16px;
    }

    .content-wrapper {
        padding: 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header-actions {
        width: 100%;
    }

    .form-row,
    .form-row-3 {
        grid-template-columns: 1fr;
    }

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

    .filters-bar .form-group {
        min-width: 0;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .modal-overlay {
        padding: 12px;
        align-items: flex-end;
    }

    .modal {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 85vh;
    }

    .table th,
    .table td {
        padding: 8px 10px;
    }

    .header-right .header-user span:not(strong) {
        display: none;
    }
}

/* ---------- Responsive: < 480px — Extra compact ---------- */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .pagination {
        flex-wrap: wrap;
    }

    .login-card {
        padding: 28px 20px;
    }

    .tabs {
        gap: 0;
    }

    .tab-link {
        padding: 8px 12px;
        font-size: 0.8125rem;
    }
}

/* ---------- Print Styles ---------- */
@media print {
    .sidebar,
    .header,
    .sidebar-backdrop,
    .page-header-actions,
    .filters-bar,
    .pagination,
    .btn,
    .toast-container,
    .modal-overlay,
    .dropdown-menu {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .content-wrapper {
        padding: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        break-inside: avoid;
    }

    .table th {
        background: none !important;
        font-weight: bold;
    }

    body {
        font-size: 11pt;
        color: #000;
        background: #fff;
    }

    a {
        color: #000;
        text-decoration: none;
    }

    .badge {
        border: 1px solid #999;
        background: none !important;
        color: #000 !important;
    }
}

/* ---------- Scrollbar (Webkit) ---------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ---------- Inline SVG Icons ---------- */
svg[stroke="currentColor"] {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.btn svg {
    vertical-align: -0.125em;
}

.sort-link svg {
    vertical-align: -0.2em;
}

/* ---------- Focus Visible Reset ---------- */
:focus:not(:focus-visible) {
    outline: none;
}

/* ---------- Selection ---------- */
::selection {
    background: rgba(59, 130, 246, 0.2);
    color: var(--color-text);
}

/* ---------- Image Gallery ---------- */
.image-gallery {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.image-gallery-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.image-preview-large {
    max-width: 480px;
    max-height: 360px;
    border-radius: var(--radius-lg);
    object-fit: contain;
    border: 1px solid var(--color-border);
}

.image-edit-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
}

.image-edit-card .image-preview {
    max-width: 200px;
    max-height: 150px;
}

.image-preview-thumb {
    width: 100px;
    height: 75px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

/* ---------- Search Select Dropdown (JS-created) ---------- */
.search-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow-y: auto;
    z-index: 200;
}

.search-select-dropdown .search-select-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--color-border);
}

.search-select-dropdown .search-select-item:last-child {
    border-bottom: none;
}

.search-select-dropdown .search-select-item:hover {
    background: var(--color-primary-light);
}

/* ---------- Stats Grid ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* ---------- Dashboard Grid ---------- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ---------- Detail Page Grid ---------- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

@media (max-width: 900px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

.detail-fields {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 20px;
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-field-full {
    grid-column: 1 / -1;
}

.detail-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.detail-value {
    font-size: 0.9375rem;
    color: var(--color-text);
}

/* ---------- Thumbnail placeholder ---------- */
.thumbnail-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 18px;
    border: 1px solid var(--color-border);
}

/* ---------- Horizontal rule ---------- */
hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 16px 0;
}

/* ---------- Page actions alias ---------- */
.page-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---------- Font weight helper ---------- */
.font-medium {
    font-weight: 500;
}

/* ---------- Table responsive wrapper ---------- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ---------- Sort link ---------- */
.sort-link {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.sort-link:hover {
    color: var(--color-primary);
    text-decoration: none;
}

/* ---------- Pagination wrapper ---------- */
.pagination-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.pagination-info {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

/* ---------- Align end (for inline forms) ---------- */
.align-end {
    align-items: flex-end;
}

/* ---------- Form row 3-column ---------- */
.form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

@media (max-width: 768px) {
    .form-row-3 {
        grid-template-columns: 1fr;
    }
}
