/* =============================================
   EEGControl App - Standalone CSS
   ============================================= */

/* --- CSS Variables --- */
:root {
    --primary: #0399a7;
    --primary-dark: #017280;
    --primary-light: rgba(3, 153, 167, 0.08);
    --accent: #56c271;
    --bg: #f1f5f9;
    --bg-sidebar: #0f1f2b;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --transition: 0.15s ease;
    --sidebar-width: 260px;
}

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

body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
p { margin: 0 0 0.5rem; }
img { max-width: 100%; display: block; }

/* =============================================
   Layout: Sidebar + Main
   ============================================= */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo {
    display: block;
    text-decoration: none;
}
.sidebar-logo:hover { text-decoration: none; }
.sidebar-logo img {
    max-width: 180px;
    height: auto;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 1.25rem;
    color: #94a3b8;
    font-size: 0.835rem;
    font-weight: 500;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all var(--transition);
}
.sidebar-link:hover {
    background: rgba(255,255,255,0.04);
    color: #e2e8f0;
    text-decoration: none;
}
.sidebar-link.active {
    background: rgba(3, 153, 167, 0.12);
    color: #5eead4;
    border-left-color: var(--primary);
}

.sidebar-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}
.sidebar-link.active .sidebar-icon { opacity: 1; }

.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 0.5rem 1.25rem;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
    margin-bottom: 0.75rem;
}

.sidebar-user-name {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #e2e8f0;
}

.sidebar-user-level {
    font-size: 0.7rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar-footer-links {
    display: flex;
    gap: 0.75rem;
}

.sidebar-footer-link {
    font-size: 0.78rem;
    color: #64748b;
    text-decoration: none;
    transition: color var(--transition);
}
.sidebar-footer-link:hover { color: #94a3b8; text-decoration: none; }

.sidebar-logout { color: #f87171 !important; }
.sidebar-logout:hover { color: #fca5a5 !important; }

/* --- Main Content Area --- */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.app-page-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text);
}

.app-page-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.app-content {
    flex: 1;
    padding: 1.5rem;
}

/* =============================================
   Components
   ============================================= */

/* --- Cards --- */
.content-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.content-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border-light);
}

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

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-align: center;
}

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

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-weight: 500;
}

/* --- Data Tables --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
    font-size: 0.835rem;
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: rgba(3, 153, 167, 0.02);
}

.data-table a { font-weight: 500; }

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #ccfbf1; color: var(--primary-dark); }
.badge-muted   { background: #f1f5f9; color: #64748b; }

/* --- Alerts --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.835rem;
    margin-bottom: 1rem;
    border-left: 3px solid transparent;
}

.alert-success { background: #f0fdf4; color: #166534; border-left-color: var(--success); }
.alert-error   { background: #fef2f2; color: #991b1b; border-left-color: var(--danger); }
.alert-warning { background: #fffbeb; color: #92400e; border-left-color: var(--warning); }
.alert-info    { background: #f0fdfa; color: var(--primary-dark); border-left-color: var(--primary); }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.835rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }

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

.btn-ghost {
    background: transparent;
    color: var(--primary-dark);
    border-color: var(--border);
}
.btn-ghost:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
}

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

.form-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.835rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.5;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(3, 153, 167, 0.1);
}

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

.form-input:disabled,
.form-select:disabled {
    background: var(--bg);
    color: var(--text-muted);
    cursor: not-allowed;
}

.input-password-wrap {
    position: relative;
}
.input-password-wrap .form-input { padding-right: 2.5rem; }
.input-password-wrap .pw-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-muted);
    font-size: 0;
    line-height: 1;
}
.input-password-wrap .pw-toggle:hover { color: var(--text); }
.input-password-wrap .pw-toggle svg { width: 18px; height: 18px; }

/* --- Form-control alias (matches form-input/form-select) --- */
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.835rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.5;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(3, 153, 167, 0.1);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled {
    background: var(--bg);
    color: var(--text-muted);
    cursor: not-allowed;
}
textarea.form-control {
    resize: vertical;
    min-height: 2.5rem;
}
select.form-control {
    appearance: auto;
}

/* --- Tab Navigation --- */
.tab-nav {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color var(--transition), border-color var(--transition);
    white-space: nowrap;
}
.tab-nav-link:hover {
    color: var(--text-secondary);
    text-decoration: none;
}
.tab-nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-nav-link .tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    border-radius: 999px;
    background: var(--bg);
    color: var(--text-muted);
}
.tab-nav-link.active .tab-badge {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* --- Text Utilities --- */
.text-muted { color: var(--text-muted); }
.text-small { font-size: 0.78rem; }

/* --- Action Row --- */
.action-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    border: none;
    padding: 0;
}

.empty-state p {
    font-size: 0.835rem;
}

/* =============================================
   Login Page (standalone, no sidebar)
   ============================================= */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 2rem;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.login-logo {
    display: block;
    margin: 0 auto 0.5rem;
    max-width: 220px;
    height: auto;
}

.login-card .login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.835rem;
    margin-bottom: 1.5rem;
}

.login-card .btn-primary {
    width: 100%;
    padding: 0.65rem 1rem;
}

/* --- Filter Row --- */
.filter-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-row .form-input,
.filter-row .form-select {
    width: auto;
}

/* --- Pager --- */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-light);
    flex-wrap: wrap;
    gap: 0.5rem;
}

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

.pager-nav {
    display: flex;
    gap: 0.25rem;
}

.pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.pager-btn:hover:not(.disabled):not(.active) {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
}

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

.pager-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* --- Sortable Table Headers --- */
.data-table thead th.sortable {
    cursor: pointer;
    position: relative;
    padding-right: 1.4rem;
    user-select: none;
    -webkit-user-select: none;
    transition: color var(--transition);
}
.data-table thead th.sortable:hover {
    color: var(--primary);
}
.data-table thead th.sortable::after {
    content: '\2195';
    position: absolute;
    right: 0.3rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.4;
}
.data-table thead th.sortable.sort-asc::after {
    content: '\25B2';
    color: var(--primary);
    opacity: 1;
}
.data-table thead th.sortable.sort-desc::after {
    content: '\25BC';
    color: var(--primary);
    opacity: 1;
}

/* --- Clickable Table Rows --- */
.data-table tbody tr[data-href],
.data-table tbody tr[data-modal-href] {
    cursor: pointer;
}
.data-table tbody tr[data-href]:hover,
.data-table tbody tr[data-modal-href]:hover {
    background: var(--primary-light);
}
.data-table tbody tr[data-href]:active,
.data-table tbody tr[data-modal-href]:active {
    background: rgba(3, 153, 167, 0.12);
}

/* --- Modal (Stacked + Draggable) --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 31, 43, 0.5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3vh 1rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    overflow-y: auto;
}
.modal-overlay.open {
    opacity: 1;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 600px;
    transform: translateY(-10px);
    transition: transform 0.2s ease;
}
.modal-overlay.open .modal {
    transform: translateY(0);
}
.modal.modal-wide {
    max-width: 900px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
.modal-header:active {
    cursor: grabbing;
}
.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    padding: 0;
    border: none;
    pointer-events: none;
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    font-size: 1.25rem;
    color: var(--text-muted);
    background: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    pointer-events: auto;
    transition: all var(--transition);
}
.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-body {
    padding: 1.25rem;
    max-height: 75vh;
    overflow-y: auto;
}

.modal-body .form-group:last-child {
    margin-bottom: 0;
}

.modal-body .alert {
    margin-bottom: 1rem;
}

.modal-footer {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

.modal-danger {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--danger);
}
.modal-danger h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--danger);
    margin-bottom: 0.5rem;
}
.modal-danger p {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* --- Confirmation Dialog --- */
.confirm-dialog {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
    margin: auto;
}

.confirm-icon {
    font-size: 2.5rem;
    color: var(--warning);
    margin-bottom: 0.75rem;
    line-height: 1;
}

.confirm-message {
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.confirm-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

/* =============================================
   Responsive
   ============================================= */

@media (max-width: 1024px) {
    :root { --sidebar-width: 220px; }
}

@media (max-width: 768px) {
    .sidebar { display: none; }
    .app-main { margin-left: 0; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .app-content { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr; }
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    min-width: 280px;
    max-width: 420px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.835rem;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-left: 3px solid transparent;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

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

.toast-success { background: #f0fdf4; color: #166534; border-left-color: var(--success); }
.toast-error   { background: #fef2f2; color: #991b1b; border-left-color: var(--danger); }
.toast-warning { background: #fffbeb; color: #92400e; border-left-color: var(--warning); }
.toast-info    { background: #f0fdfa; color: var(--primary-dark); border-left-color: var(--primary); }

.toast-icon {
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1.4;
}

.toast-message {
    flex: 1;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    opacity: 0.5;
    padding: 0;
    color: inherit;
}

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