/* =============================================
   CSS RESET & VARIABLES
   
   THEMING: Change these CSS variables to customize
   colors and appearance without touching the rest
   of the CSS. All components use these variables.
   ============================================= */

:root {
    /* ========== COLOR PALETTE ========== */
    /* Primary colors - change these for brand */
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-light: #eef2ff;

    /* Neutral colors */
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;

    /* Text colors */
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;

    /* Semantic colors */
    --color-success: #22c55e;
    --color-success-bg: #f0fdf4;
    --color-warning: #f59e0b;
    --color-warning-bg: #fffbeb;
    --color-error: #ef4444;
    --color-error-bg: #fef2f2;

    /* ========== SPACING ========== */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* ========== TYPOGRAPHY ========== */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;

    /* ========== BORDERS & SHADOWS ========== */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-full: 9999px;

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

    /* ========== LAYOUT ========== */
    --container-max: 1600px;
    --header-height: 64px;
}

/* =============================================
   BASE RESET
   ============================================= */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

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

a:hover {
    text-decoration: underline;
}

/* =============================================
   LAYOUT
   ============================================= */

.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

.main-content {
    flex: 1;
    padding: var(--space-xl) 0;
}

/* =============================================
   HEADER
   ============================================= */

.header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-text);
}

.logo-img {
    height: 28px;
    width: auto;
}

.logo-text {
    line-height: 1;
}

.logo:hover {
    text-decoration: none;
}

.nav {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.nav-link {
    color: var(--color-text-secondary);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

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

.nav-link--admin {
    color: var(--color-primary);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding-left: var(--space-md);
    border-left: 1px solid var(--color-border);
}

.user-name {
    font-weight: 500;
}

.user-role {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* =============================================
   FOOTER
   ============================================= */

.footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: var(--space-lg) 0;
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* =============================================
   BUTTONS
   ============================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-size-base);
    font-weight: 500;
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

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

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

.btn--outline {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text);
}

.btn--outline:hover {
    background: var(--color-bg);
    border-color: var(--color-text-muted);
}

.btn--danger {
    background: var(--color-error);
    color: white;
}

.btn--danger:hover {
    background: #dc2626;
}

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

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

.btn--sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
}

.btn--block {
    width: 100%;
}

/* =============================================
   FORMS
   ============================================= */

.form {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-label {
    font-weight: 500;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.form-input,
.form-select,
.form-textarea {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-base);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-input--sm,
.form-select--sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
}

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

.form-actions {
    display: flex;
    gap: var(--space-md);
    padding-top: var(--space-md);
}

.inline-form {
    display: inline;
}

/* =============================================
   CONTENT FORMS (full-width page forms)
   ============================================= */

.content-form {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}

.form-section {
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-xl);
    border-bottom: 1px solid var(--color-border);
}

.form-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.form-section h3 {
    margin-bottom: var(--space-md);
    color: var(--color-text);
    font-size: var(--font-size-lg);
}

.form-hint {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
}

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

/* Roles Grid (for user form) */
.roles-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.role-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.role-item:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.role-checkbox {
    margin-top: 0.2rem;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.role-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.role-icon {
    font-size: var(--font-size-xl);
    line-height: 1;
}

.role-name {
    font-weight: 600;
    color: var(--color-text);
    text-transform: capitalize;
}

.role-desc {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* Permissions Grid (for role form) */
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-lg);
}

.permission-group {
    background: var(--color-bg);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    border: 1px solid var(--color-border);
}

.permission-group-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
}

.permission-group-icon {
    font-size: var(--font-size-xl);
}

.permission-group-name {
    font-weight: 600;
    flex: 1;
}

.permission-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.permission-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.permission-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.permission-checkbox {
    margin-top: 0.2rem;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.permission-info {
    display: flex;
    flex-direction: column;
}

.permission-name {
    font-weight: 500;
    color: var(--color-text);
}

.permission-desc {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* Button sizes */
.btn--xs {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
}

/* Content form actions */
.content-form .form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--color-border);
}

/* =============================================
   CARDS
   ============================================= */

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

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

/* =============================================
   ALERTS / FLASH MESSAGES (Floating Toasts)
   ============================================= */

/* Toast container - floats in top-right corner */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + var(--space-md));
    right: var(--space-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: 400px;
    pointer-events: none;
}

.toast-container .alert {
    pointer-events: auto;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease-out;
}

/* Solid backgrounds for floating toasts - better readability */
.toast-container .alert--success {
    background: #16a34a;
    color: white;
    border: none;
}

.toast-container .alert--error {
    background: #dc2626;
    color: white;
    border: none;
}

.toast-container .alert--warning {
    background: #d97706;
    color: white;
    border: none;
}

.toast-container .alert--info {
    background: #2563eb;
    color: white;
    border: none;
}

.toast-container .alert-close {
    color: white;
    opacity: 0.8;
}

.toast-container .alert-close:hover {
    opacity: 1;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Inline alerts (for form validation errors) */
.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.alert--success {
    background: var(--color-success-bg);
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert--error {
    background: var(--color-error-bg);
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert--warning {
    background: var(--color-warning-bg);
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert--info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.alert-close {
    background: none;
    border: none;
    font-size: var(--font-size-xl);
    cursor: pointer;
    opacity: 0.5;
    margin-left: var(--space-md);
}

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

.error-list {
    margin: 0;
    padding-left: var(--space-lg);
}

/* =============================================
   BADGES
   ============================================= */

.badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border-radius: var(--radius-full);
}

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

.badge--secondary {
    background: var(--color-bg);
    color: var(--color-text-secondary);
}

.badge--success {
    background: var(--color-success-bg);
    color: #166534;
}

.badge--error {
    background: var(--color-error-bg);
    color: #991b1b;
}

/* =============================================
   TABLES
   ============================================= */

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

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

.table th,
.table td {
    padding: var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tbody tr:hover {
    background: var(--color-bg);
}

.row--inactive {
    opacity: 0.5;
}

.action-buttons {
    display: flex;
    gap: var(--space-xs);
}

.reset-password-form {
    margin-top: var(--space-sm);
    display: flex;
    gap: var(--space-sm);
}

/* =============================================
   PAGE HEADERS
   ============================================= */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
}

.page-title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
}

.page-subtitle {
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
}

/* =============================================
   STATS GRID (Admin Dashboard)
   ============================================= */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.stat-icon {
    font-size: var(--font-size-3xl);
}

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: 700;
}

.stat-label {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* =============================================
   NOTES GRID
   ============================================= */

.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-lg);
}

.note-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s;
}

.note-card:hover {
    box-shadow: var(--shadow-md);
}

.note-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.note-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.note-date {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.note-content {
    color: var(--color-text-secondary);
    flex: 1;
    margin-bottom: var(--space-lg);
}

.note-actions {
    display: flex;
    gap: var(--space-sm);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
}

/* =============================================
   PAGINATION
   ============================================= */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-lg);
    margin-top: var(--space-xl);
}

.pagination-link {
    color: var(--color-primary);
}

.pagination-info {
    color: var(--color-text-muted);
}

/* =============================================
   EMPTY STATE
   ============================================= */

.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--color-text-muted);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: var(--space-lg);
}

.empty-state h2 {
    color: var(--color-text);
    margin-bottom: var(--space-sm);
}

.empty-state p {
    margin-bottom: var(--space-lg);
}

/* =============================================
   AUTH PAGES
   ============================================= */

.auth-container {
    min-height: calc(100vh - var(--header-height) - 200px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.auth-title {
    font-size: var(--font-size-2xl);
    text-align: center;
    margin-bottom: var(--space-xs);
}

.auth-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xl);
}

.auth-footer {
    text-align: center;
    margin-top: var(--space-xl);
    color: var(--color-text-muted);
}

/* =============================================
   ERROR PAGES
   ============================================= */

.error-page {
    min-height: calc(100vh - var(--header-height) - 200px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-content {
    text-align: center;
}

.error-code {
    font-size: 6rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1;
}

.error-title {
    font-size: var(--font-size-2xl);
    margin: var(--space-md) 0;
}

.error-message {
    color: var(--color-text-muted);
    margin-bottom: var(--space-xl);
}

.error-details {
    margin: var(--space-xl) 0;
    text-align: left;
    background: var(--color-bg);
    padding: var(--space-md);
    border-radius: var(--radius-md);
}

.error-details pre {
    white-space: pre-wrap;
    font-size: var(--font-size-sm);
}

/* =============================================
   UTILITIES
   ============================================= */

.text-center {
    text-align: center;
}

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

/* =============================================
   RESPONSIVE
   ============================================= */

@media (max-width: 768px) {

    /* Reduce base font size for mobile */
    html {
        font-size: 14px;
    }

    /* Header: always single row, no wrap */
    .header {
        height: auto;
        min-height: var(--header-height);
    }

    .header-inner {
        flex-wrap: nowrap;
        height: auto;
        min-height: var(--header-height);
        padding: 0.5rem var(--space-sm);
        gap: var(--space-sm);
    }

    .logo {
        font-size: 1rem;
        flex-shrink: 0;
    }

    .nav {
        flex-shrink: 0;
        gap: var(--space-xs);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-md);
    }

    .page-title {
        font-size: var(--font-size-xl);
    }

    .page-subtitle {
        font-size: var(--font-size-sm);
    }

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

    /* Container - reduce horizontal padding */
    .container {
        padding: 0 var(--space-sm);
    }

    .main-content {
        padding: var(--space-md) 0;
    }

    /* Cards - reduce padding on mobile */
    .card {
        padding: var(--space-md);
    }

    /* Tables - make scrollable and hide less important columns */
    .table-responsive {
        margin: 0 calc(-1 * var(--space-md));
        padding: 0 var(--space-md);
    }

    .table th,
    .table td {
        padding: var(--space-sm);
        font-size: var(--font-size-sm);
    }

    .table .hide-mobile {
        display: none;
    }

    /* Action buttons - stack vertically if needed */
    .action-buttons {
        flex-wrap: wrap;
    }

    /* Badges - smaller */
    .badge {
        padding: 0.15rem 0.4rem;
        font-size: 0.75rem;
    }
}