/* ==========================================================================
   KSM Projects - Base Stylesheet & Component System
   ========================================================================== */

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    transition: background-color var(--transition-speed), color var(--transition-speed);
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s ease;
}
a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Layout Structure: App Layout + Sidebar + Main Content + Top Header
   ========================================================================== */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* Fixed Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    max-width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.04);
}

.sidebar-header {
    height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none !important;
    color: inherit;
}

.brand-logo {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFF;
    font-weight: 800;
    font-size: 15px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--sidebar-text);
}

/* Sidebar Workspace Context Switcher */
.sidebar-workspace {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sidebar-workspace label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--sidebar-muted);
    display: block;
    margin-bottom: 6px;
}
.ws-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-hover);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.15s ease;
}
.ws-selector:hover {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb, 99, 102, 241), 0.06);
}
.ws-avatar {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--primary);
    color: #FFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.ws-info {
    flex: 1;
    min-width: 0;
}
.ws-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--sidebar-text);
}
.ws-role {
    font-size: 11px;
    color: var(--sidebar-muted);
}

/* Sidebar Navigation Items */
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nav-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    letter-spacing: 0.8px;
    padding: 12px 12px 6px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    transition: all 0.15s ease;
    text-decoration: none !important;
}
.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}
.nav-item.active {
    background: var(--primary);
    color: #FFF;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.nav-item.active span {
    color: #FFF;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--sidebar-bg);
    flex-shrink: 0;
}

/* Main Content Area (Offset for Fixed Sidebar) */
.main-content {
    margin-left: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100% - 260px);
    min-width: 0;
    background-color: var(--bg-body);
}

/* Top Sticky Header */
.top-header {
    height: 64px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}
.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    color: var(--text-muted);
}
.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
}
.breadcrumb a:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* Content Body */
.content-body {
    padding: 24px 28px;
    flex: 1;
    width: 100%;
}

/* ==========================================================================
   Grids & Layout Helpers
   ========================================================================== */
.grid {
    display: grid;
    gap: 20px;
}
.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s ease; }
    .main-content { margin-left: 0; width: 100%; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Cards, Badges, Stat Cards
   ========================================================================== */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    box-shadow: var(--shadow-card);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}
.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
}
.card-desc {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-card {
    padding: 16px 20px;
}
.stat-label {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 500;
}
.stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-main);
    margin: 4px 0 2px;
    letter-spacing: -0.5px;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
}
.badge-primary { background: rgba(var(--primary-rgb, 99, 102, 241), 0.12); color: var(--primary); }
.badge-secondary { background: rgba(var(--secondary-rgb, 236, 72, 153), 0.12); color: var(--secondary); }
.badge-success { background: rgba(16, 185, 129, 0.12); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.badge-info { background: rgba(6, 182, 212, 0.12); color: #0891b2; }

/* Progress Bar */
.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--bg-hover);
    border-radius: 9999px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 9999px;
    background: var(--primary);
    transition: width 0.3s ease;
}

/* ==========================================================================
   Buttons & Forms
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 16px;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none !important;
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: #FFF;
    border-color: var(--primary);
}
.btn-primary:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.btn-outline {
    background: transparent;
    color: var(--text-main);
    border-color: var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* Form Controls */
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 13.5px;
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease;
    font-family: inherit;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb, 99, 102, 241), 0.15);
}
textarea.form-control {
    resize: vertical;
}

/* ==========================================================================
   Tables
   ========================================================================== */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    text-align: left;
}
.table th {
    background: var(--bg-hover);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}
.table tbody tr:hover td {
    background: var(--bg-hover);
}

/* ==========================================================================
   Theme Switcher Floating Widget
   ========================================================================== */
.theme-switcher-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
    padding: 12px 16px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 12.5px;
    backdrop-filter: blur(8px);
}
.theme-switcher-widget.is-sidebar {
    position: static;
    bottom: auto;
    right: auto;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    border-radius: 0;
    box-shadow: none;
    padding: 0 0 0.75rem 0;
    margin-bottom: 0.75rem;
    z-index: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    backdrop-filter: none;
}
.theme-switcher-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.theme-switcher-title {
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
}
.theme-switcher-mode-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    margin: 0;
    user-select: none;
    color: var(--text-muted);
}
.theme-switcher-controls {
    display: flex;
    align-items: center;
}
.theme-switcher-select {
    padding: 4px 8px;
    font-size: 0.75rem;
    width: 100%;
    font-weight: 600;
}
