/* Font Import */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Color Palette - Light Theme */
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --background-bg: #f3f4f6;
    --surface-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --danger-color: #ef4444;

    /* Layout Variables */
    --sidebar-width: 260px;
    /* Default sidebar width */
    --header-height: 64px;
    --resizer-width: 4px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background-bg);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

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

ul {
    list-style: none;
}

/* ===========================
   Components
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.875rem;
}

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

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

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.card {
    background-color: var(--surface-bg);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 2rem;
}

/* ===========================
   Login Page
   =========================== */
.login-container {
    min-height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
}

/* ===========================
   Admin Layout (Resizable)
   =========================== */
.admin-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    /* Controlled by JS or CSS variable */
    min-width: 50px;
    max-width: 600px;
    background-color: var(--surface-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 20;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.alert-danger {
    text-align: center;
    position: relative;
    padding: 0.75rem 1.25rem;
    margin-bottom: 1rem;
    color: var(--danger-color);
    font-weight: bold;
    /* border: 1px solid transparent;
    border-radius: 0.35rem;
    color: #721c24; */
    /* background-color: #f8d7da;
    border-color: #f5c6cb; */

    /* 讓文字與背景有更好的對比度 */
    font-family: sans-serif;
    font-size: 0.9rem;
    line-height: 1.5;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link:hover,
.nav-link.active {
    background-color: #f8fafc;
    color: var(--primary-color);
    border-left: 3px solid var(--primary-color);
}

.nav-icon {
    width: 24px;
    margin-right: 0.75rem;
    text-align: center;
    flex-shrink: 0;
}

/* Resizer Handle */
.resizer {
    width: var(--resizer-width);
    background-color: transparent;
    cursor: col-resize;
    z-index: 30;
    transition: background-color 0.2s;
    height: 100%;
    flex-shrink: 0;
}

.resizer:hover,
.resizer.resizing {
    background-color: var(--primary-color);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Prevent flex item from overflowing */
    overflow: hidden;
}

.top-header {
    height: var(--header-height);
    background-color: var(--surface-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    flex-shrink: 0;
}

.hamburger-btn {
    display: none;
    /* Hidden on desktop */
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
}

.content-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* Nested Menu */
.submenu {
    max-height: 0;
    overflow: hidden;
    background-color: #f8fafc;
    transition: max-height 0.3s ease;
}

.nav-item.open .submenu {
    max-height: 500px;
}

.submenu-link {
    display: block;
    padding: 0.5rem 1.5rem 0.5rem 3.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.nav-arrow {
    margin-left: auto;
    transition: transform 0.2s;
}

.nav-item.open .nav-arrow {
    transform: rotate(180deg);
}

/* User Dropdown */
.user-menu {
    position: relative;
    margin-left: auto;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 200px;
    background-color: white;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-radius: 0.375rem;
    display: none;
    z-index: 100;
}

.user-menu.active .dropdown-menu {
    display: block;
}

/* ===========================
   RWD - Mobile (< 768px)
   =========================== */
@media (max-width: 768px) {

    /* Disable resizer on mobile */
    .resizer {
        display: none;
    }

    /* Sidebar becomes off-canvas overlay */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 260px !important;
        /* Fixed width on mobile */
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .hamburger-btn {
        display: block;
        margin-right: 1rem;
    }

    /* Overlay */
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 19;
        /* Just below sidebar */
        display: none;
    }

    .mobile-overlay.active {
        display: block;
    }
}


/* ===========================
   Error Pages
   =========================== */
.error-icon {
    font-size: 5rem;
    color: var(--danger-color);
    margin-bottom: 1rem;
}

.error-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

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