/* =========================================================
   THEME: Clean Enterprise
   FILE: theme.css
   DESCRIPTION:
   - Light, professional enterprise look
   - Subtle depth, restrained animations
   - Dark mode via [data-theme="dark"] on <html> or <body>
   ========================================================= */

/* -------------------------
   1. CSS RESET / BASE
   ------------------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: "Open Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 0.875rem; /* 14px */
    line-height: 1.5;
    color: #1f2933;
    background-color: #f4f6f8;
}

/* Utility containers */

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px 40px 20px;
}

/* Smooth transitions */

body,
button,
input,
select,
textarea,
.card,
.widget,
.navbar,
.sidebar {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease,
                box-shadow 0.25s ease, transform 0.18s ease;
}

/* Links */

a {
    color: #165996;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Headings */

h1, h2, h3, h4, h5 {
    font-weight: 600;
    color: #102a43;
    margin-bottom: 0.5rem;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }

/* -------------------------
   2. THEME TOKENS
   ------------------------- */

:root {
    --color-bg: #f4f6f8;
    --color-surface: #ffffff;
    --color-surface-alt: #f9fafb;

    --color-border-subtle: #d0d7e2;
    --color-border-strong: #98a6bc;

    --color-primary: #173f5f;
    --color-primary-light: #20639b;
    --color-primary-soft: #e0e8f5;

    --color-accent: #3caea3;
    --color-accent-soft: #e5f6f4;

    --color-danger: #d64545;
    --color-danger-soft: #fdecea;

    --color-warning: #f6c343;
    --color-warning-soft: #fff4d6;

    --color-success: #2e8540;
    --color-success-soft: #e6f4ea;

    --color-text-main: #1f2933;
    --color-text-muted: #6b7b93;
    --color-text-inverse: #ffffff;

    --shadow-soft: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-medium: 0 4px 10px rgba(15, 23, 42, 0.12);

    --radius-small: 4px;
    --radius-medium: 6px;
    --radius-large: 10px;

    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
}

/* -------------------------
   3. DARK MODE
   - activate via:
   - <body data-theme="dark"> or <html data-theme="dark">
   ------------------------- */

[data-theme="dark"] {
    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-surface-alt: #111827;

    --color-border-subtle: #374151;
    --color-border-strong: #4b5563;

    --color-primary: #4b91e2;
    --color-primary-light: #76a9fa;
    --color-primary-soft: #111827;

    --color-accent: #34d399;
    --color-accent-soft: #022c22;

    --color-danger: #f97373;
    --color-danger-soft: #3f1f1f;

    --color-warning: #facc15;
    --color-warning-soft: #3b2f1a;

    --color-success: #4ade80;
    --color-success-soft: #022c22;

    --color-text-main: #e5e7eb;
    --color-text-muted: #9ca3af;
    --color-text-inverse: #111827;
}

/* Apply theme variables */

body {
    background-color: var(--color-bg);
    color: var(--color-text-main);
}

/* -------------------------
   4. LAYOUT: NAVBAR & SIDEBAR
   ------------------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
    background-color: var(--color-bg);
}

/* Top navbar */

.navbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: var(--color-surface);
    box-shadow: var(--shadow-soft);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.navbar__logo {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
}

.navbar__title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--color-text-main);
}

.navbar__nav {
    display: flex;
    align-items: center;
    gap: 16px;
}

.navbar__link {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.navbar__link--active {
    color: var(--color-primary);
    font-weight: 600;
}

/* Sidebar (optional) */

.sidebar {
    width: 220px;
    background-color: var(--color-surface);
    border-right: 1px solid var(--color-border-subtle);
    padding: 16px 12px 24px 12px;
    box-shadow: var(--shadow-soft);
}

.sidebar__section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin: 8px 12px 6px 12px;
}

.sidebar__link {
    display: block;
    padding: 7px 12px;
    border-radius: var(--radius-small);
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.sidebar__link:hover {
    background-color: var(--color-primary-soft);
    color: var(--color-primary);
    text-decoration: none;
}

.sidebar__link--active {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
    font-weight: 600;
}

/* Main content */

.app-main {
    flex: 1;
    padding: 20px 24px 40px 24px;
}

/* -------------------------
   5. BUTTONS
   ------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius-small);
    border: 1px solid transparent;
    padding: 7px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    background-color: var(--color-surface);
    color: var(--color-text-main);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Primary */

.btn--primary {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-soft);
}

.btn--primary:hover:not(:disabled) {
    background-color: var(--color-primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-medium);
}

/* Secondary */

.btn--secondary {
    background-color: var(--color-surface);
    border-color: var(--color-border-subtle);
    color: var(--color-text-main);
}

.btn--secondary:hover:not(:disabled) {
    background-color: var(--color-surface-alt);
}

/* Ghost */

.btn--ghost {
    background-color: transparent;
    border-color: transparent;
    color: var(--color-text-muted);
}

.btn--ghost:hover:not(:disabled) {
    background-color: var(--color-primary-soft);
    color: var(--color-primary);
}

/* Status */

.btn--danger {
    background-color: var(--color-danger);
    border-color: var(--color-danger);
    color: var(--color-text-inverse);
}

.btn--danger:hover:not(:disabled) {
    background-color: #c23333;
}

/* Sizes */

.btn--sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn--lg {
    padding: 9px 18px;
    font-size: 0.95rem;
}

/* -------------------------
   6. FORMS
   ------------------------- */

.form-group {
    margin-bottom: var(--spacing-md);
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-small);
    padding: 7px 9px;
    font-size: 0.85rem;
    background-color: var(--color-surface);
    color: var(--color-text-main);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 2px rgba(23, 63, 95, 0.12);
}

/* Inline form row */

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

/* -------------------------
   7. TABLES
   ------------------------- */

.table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--color-surface);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
    font-size: 0.85rem;
}

.table thead {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
}

.table th,
.table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.table th {
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.table tbody tr:hover {
    background-color: var(--color-primary-soft);
}

/* Compact tables */

.table--compact th,
.table--compact td {
    padding: 5px 8px;
}

/* Status tags */

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.75rem;
}

.badge--success {
    background-color: var(--color-success-soft);
    color: var(--color-success);
}

.badge--danger {
    background-color: var(--color-danger-soft);
    color: var(--color-danger);
}

.badge--warning {
    background-color: var(--color-warning-soft);
    color: var(--color-warning);
}

.badge--muted {
    background-color: var(--color-primary-soft);
    color: var(--color-text-muted);
}

/* -------------------------
   8. CARDS / WIDGETS / PANELS
   ------------------------- */

.card,
.widget {
    background-color: var(--color-surface);
    border-radius: var(--radius-medium);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-soft);
}

.card + .card,
.widget + .widget {
    margin-top: var(--spacing-md);
}

.card__header,
.widget__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.card__title,
.widget__title {
    font-size: 0.95rem;
    font-weight: 600;
}

.card__subtitle,
.widget__subtitle {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Dashboard layout */

.dashboard {
    display: grid;
    grid-template-columns: 2fr 1.4fr;
    grid-gap: 16px;
    margin-top: 12px;
}

.dashboard__primary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-gap: 12px;
}

.dashboard__secondary {
    display: grid;
    grid-template-rows: auto auto;
    grid-gap: 12px;
}

/* Metric tiles */

.metric-tile {
    background-color: var(--color-surface);
    border-radius: var(--radius-medium);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-tile__label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.metric-tile__value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--color-text-main);
}

.metric-tile__trend {
    font-size: 0.8rem;
    color: var(--color-success);
}

/* -------------------------
   9. ALERTS / MESSAGES
   ------------------------- */

.alert {
    border-radius: var(--radius-small);
    padding: 8px 10px;
    font-size: 0.8rem;
    margin-bottom: var(--spacing-md);
}

.alert--info {
    background-color: var(--color-primary-soft);
    color: var(--color-primary);
}

.alert--success {
    background-color: var(--color-success-soft);
    color: var(--color-success);
}

.alert--warning {
    background-color: var(--color-warning-soft);
    color: var(--color-warning);
}

.alert--danger {
    background-color: var(--color-danger-soft);
    color: var(--color-danger);
}

/* -------------------------
   10. MODALS (BASIC)
   ------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal {
    background-color: var(--color-surface);
    border-radius: var(--radius-medium);
    box-shadow: var(--shadow-medium);
    padding: 16px 18px 18px 18px;
    max-width: 520px;
    width: 100%;
    animation: modalIn 0.24s ease-out;
}

.modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.modal__title {
    font-size: 1rem;
    font-weight: 600;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* -------------------------
   11. PAGE TITLES & BREADCRUMBS
   ------------------------- */

.page-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 16px;
}

.page-header__title {
    font-size: 1.4rem;
    font-weight: 600;
}

.page-header__meta {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.breadcrumbs {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.breadcrumbs span + span::before {
    content: "�";
    margin: 0 4px;
    color: var(--color-border-strong);
}

/* -------------------------
   12. UTILITIES
   ------------------------- */

.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }

.mt-xs { margin-top: var(--spacing-xs); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }

.mb-xs { margin-bottom: var(--spacing-xs); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }

/* -------------------------
   13. SIMPLE ANIMATED PAGE FADE
   ------------------------- */

.page-animate {
    animation: pageFadeIn 0.35s ease-out;
}

@keyframes pageFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sidebar section headers */
.sidebar__section-title {
    padding: 8px 12px;
    margin-top: 16px;
    margin-bottom: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;

    color: var(--color-text-muted);
    background: var(--color-surface-alt);
    text-align: left;
    border-left: none;
}

.sidebar__section-title {
    background: var(--surface-alt);
    color: var(--text-strong);
}

/* Soft gradient background for login screens */
.login-bg {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}


/* Floating card effect */
.card {
    border-radius: 12px;
    box-shadow:
        0 8px 20px rgba(0,0,0,0.15),
        0 2px 6px rgba(0,0,0,0.1);
}

/* Sidebar toggle button */
.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
    cursor: pointer;
}

/* Collapsible sidebar */
.sidebar {
    width: 220px;
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: 60px;
    overflow-x: hidden;
}

/* Hide section titles when collapsed */
.sidebar.collapsed .sidebar__section-title {
    display: none;
}

/* Collapse link text but keep padding for alignment */
.sidebar.collapsed .sidebar__link {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
    padding-left: 12px;
}

/* Smooth fade for text */
.sidebar__link,
.sidebar__section-title {
    transition: opacity 0.25s ease;
}

/* Remove green border and left-align titles */
.sidebar__section-title {
    padding: 8px 12px;
    margin-top: 16px;
    margin-bottom: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    background: var(--color-surface-alt);
    text-align: left;
    border-left: none;
}

/* -----------------------------------------
   COLLAPSIBLE SIDEBAR WITH HOVER EXPAND
   ----------------------------------------- */

.sidebar {
    width: 220px;
    transition: width 0.25s ease;
    overflow: hidden;
}

/* Collapsed state */
.sidebar.collapsed {
    width: 60px;
}

/* Fade text smoothly */
.sidebar__link,
.sidebar__section-title {
    transition: opacity 0.25s ease;
}

/* Hide section titles when collapsed */
.sidebar.collapsed .sidebar__section-title {
    opacity: 0;
    pointer-events: none;
}

/* Fade link text when collapsed */
.sidebar.collapsed .sidebar__link {
    opacity: 0;
}

/* Keep padding so hover area remains */
.sidebar.collapsed .sidebar__link {
    padding-left: 12px;
}

/* Hover-expand behavior */
.sidebar.collapsed:hover {
    width: 220px;
}

/* When expanded on hover, fade text back in */
.sidebar.collapsed:hover .sidebar__link,
.sidebar.collapsed:hover .sidebar__section-title {
    opacity: 1;
}

/* Toggle button */
.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
    cursor: pointer;
}

.alert-box {
    margin: 1em 0;
    padding: 0.75em 1em;
    border-radius: 4px;
    font-weight: 500;
    background-color: #e6f7e6; /* light green for success */
    border: 1px solid #4CAF50; /* green border */
    color: #2e7d32; /* dark green text */
}

.alert-box.error {
    background-color: #fdecea; /* light red for error */
    border: 1px solid #f44336; /* red border */
    color: #c62828; /* dark red text */
}

#overlay {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black */
    z-index: 9999; /* Sit on top of everything */
    color: white;
    text-align: center;
    padding-top: 20%;
}

#overlay img {
    width: 80px;
    height: auto;
}