/* style.css */
:root {
    --bg-main: #f5f5f5;
    --bg-sidebar: #2c2c2c;
    --text-main: #333;
    --text-sidebar: #eaeaea;
    --accent: #000;
    --border-radius: 12px;
    --transition-speed: 0.3s;
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 65px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-speed) ease-in-out;
    position: fixed;
    height: 100vh;
    z-index: 1000;
    left: 0;
    top: 0;
    overflow-x: hidden;
}

.sidebar.closed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.closed .sidebar-logo {
    padding: 20px 5px;
}

.sidebar.closed .sidebar-logo img {
    max-width: 40px;
    margin: 0 auto;
    display: block;
}

.sidebar.closed .sidebar-menu .text {
    opacity: 0;
    visibility: hidden;
    white-space: nowrap;
    width: 0;
}

.sidebar.closed .sidebar-menu a, 
.sidebar.closed .sidebar-menu .menu-toggle {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar.closed .submenu {
    position: fixed;
    left: 65px;
    /* top will be set by JS */
    width: 220px;
    background-color: var(--bg-sidebar);
    box-shadow: 4px 4px 15px rgba(0,0,0,0.3);
    border-radius: 0 8px 8px 0;
    padding: 10px 0;
    z-index: 1001;
    display: none;
}

.sidebar.closed .submenu.open {
    display: block !important;
}

.sidebar.closed .submenu a {
    padding-left: 20px;
}

.sidebar-logo {
    padding: 20px;
    text-align: center;
    transition: padding var(--transition-speed);
}

.sidebar-logo img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
}

.sidebar-menu {
    list-style: none;
    padding: 20px 0;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-menu li {
    position: relative;
}

.sidebar-menu a,
.sidebar-menu .menu-toggle {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-sidebar);
    text-decoration: none;
    transition: all var(--transition-speed);
    cursor: pointer;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-menu a .icon,
.sidebar-menu .menu-toggle .icon {
    display: inline-flex;
    margin-right: 15px;
    align-items: center;
    justify-content: center;
    min-width: 24px;
}

.sidebar-menu a .text,
.sidebar-menu .menu-toggle .text {
    transition: opacity var(--transition-speed), width var(--transition-speed);
}

.sidebar-menu a:hover,
.sidebar-menu .menu-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.sidebar-menu > li > a.active,
.sidebar-menu > li > .menu-toggle.active {
    background-color: #e0e0e0;
    color: #000;
    border-left: 4px solid var(--accent);
    font-weight: 600;
}

.sidebar-menu > li > a.active .icon,
.sidebar-menu > li > .menu-toggle.active .icon {
    color: #000;
}

.submenu {
    list-style: none;
    background-color: rgba(255, 255, 255, 0.05);
    display: none;
}

.submenu.open {
    display: block;
}

.submenu a {
    padding-left: 40px;
    font-size: 13px;
}

.submenu a.active {
    background-color: #4a4a4a;
    color: #fff;
    border-left: 4px solid #fff;
}

/* Main Content */
.main-wrapper {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-speed) ease-in-out, width var(--transition-speed) ease-in-out;
    width: calc(100% - var(--sidebar-width));
    min-width: 0; /* fixes flex child overflow */
}

.main-wrapper.full {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
}

/* Header */
header {
    background-color: #fff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border-bottom-left-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
    margin: 0 10px 10px 10px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-left h2 {
    font-size: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toggle-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--accent);
    flex-shrink: 0; /* Prevents toggle from shrinking/disappearing */
    padding: 5px;
}

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

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

.user-role {
    font-size: 12px;
    color: #666;
    background: #e0e0e0;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 5px;
}

.logout-btn {
    text-decoration: none;
    color: #fff;
    background-color: var(--accent);
    padding: 6px 12px;
    border-radius: var(--border-radius);
    font-size: 14px;
    transition: background 0.2s;
}

.logout-btn:hover {
    background-color: #333;
}

/* Content Area */
.content {
    padding: 20px;
    background: #fff;
    border-radius: var(--border-radius);
    margin: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    min-height: calc(100vh - 100px);
    overflow-x: auto; /* allows table scrolling on small screens */
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

table th,
table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

table th {
    background-color: #f9f9f9;
    font-weight: 600;
}

table tr:nth-child(even) {
    background-color: #fcfcfc;
}

table tr:hover {
    background-color: #f0f0f0;
}

/* Disabled rows */
.row-disabled {
    opacity: 0.5;
}

/* Buttons */
.btn {
    padding: 8px 15px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    background-color: var(--accent);
    color: #fff;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    transition: background 0.2s;
}

td .btn {
    margin-right: 5px;
    margin-bottom: 5px;
}

.btn:hover {
    background-color: #333;
}

.btn-danger {
    background-color: #d9534f;
}

.btn-danger:hover {
    background-color: #c9302c;
}

.btn-secondary {
    background-color: #6c757d;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-family: inherit;
}

/* Modal / Popup Form */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #fff;
    padding: 30px;
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
}

.modal-close:hover {
    background-color: #d9534f;
    color: #fff;
}

/* Toast Messages */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.toast {
    background-color: var(--accent);
    color: white;
    padding: 15px 25px;
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Progress bar for AI */
#ai-progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

#ai-progress-overlay.active {
    display: flex;
}

.progress-bar-container {
    width: 300px;
    height: 10px;
    background: #eee;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-bar {
    width: 50%;
    height: 100%;
    background: var(--accent);
    animation: indeterminate 1.5s infinite linear;
    transform-origin: 0% 50%;
}

@keyframes indeterminate {
    0% {
        transform: translateX(-100%) scaleX(0.2);
    }

    100% {
        transform: translateX(200%) scaleX(0.5);
    }
}

/* Mobile responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%); /* completely hide on mobile by default */
        width: var(--sidebar-width);
    }
    .sidebar.closed {
        transform: translateX(-100%);
    }

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

    .main-wrapper {
        margin-left: 0;
        width: 100%;
    }
    
    .main-wrapper.full {
        margin-left: 0;
        width: 100%;
    }
}

/* Login Window (Centered) */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    background-color: var(--bg-main);
}

.login-box {
    background: #fff;
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-box h2 {
    margin-bottom: 20px;
}

.login-box .btn {
    width: 100%;
    margin-top: 10px;
}