/* ============================================================
   TokensCloud — Main Layout & Base Styles
   ============================================================ */

/* ----- Reset ----- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    color: var(--text-primary);
    background: var(--bg-body);
    line-height: var(--line-height-normal);
    min-height: 100vh;
}

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

img { max-width: 100%; }

/* ----- App Layout ----- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    padding-top: 48px; /* header height */
}

/* ----- Header ----- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-sticky);
    height: 48px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--box-shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-8);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.header-logo {
    height: 32px;
}

.header-app-name {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--gray-800);
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-5);
}

/* ----- Global Search ----- */
.global-search {
    position: relative;
}

.global-search-input {
    width: 220px;
    padding: 6px 12px;
    font-size: var(--font-size-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: all var(--transition-normal);
    color: var(--text-primary);
}

.global-search-input:focus {
    width: 300px;
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,102,204,0.1);
    background: var(--bg-input);
}

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

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 350px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-lg);
    z-index: var(--z-dropdown);
    display: none;
}

.search-results-dropdown.active {
    display: block;
}

.search-result-item {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-color-light);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.search-result-item:hover {
    background: var(--bg-secondary);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-type {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.search-result-title {
    font-size: var(--font-size-md);
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
}

/* ----- User Menu ----- */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 6px 12px;
    background: var(--gray-100);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    color: var(--gray-700);
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-md);
    transition: all var(--transition-normal);
}

.user-menu:hover {
    background: var(--gray-200);
    border-color: var(--gray-400);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-xl);
    z-index: var(--z-dropdown);
    display: none;
}

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

.user-menu-item {
    display: block;
    padding: var(--space-4) var(--space-7);
    color: var(--gray-700);
    text-decoration: none;
    font-size: var(--font-size-md);
    transition: background var(--transition-fast);
}

.user-menu-item:hover {
    background: var(--gray-100);
    text-decoration: none;
}

.user-menu-divider {
    height: 1px;
    background: var(--gray-200);
    margin: var(--space-2) 0;
}

/* ----- Sidebar ----- */
.sidebar {
    width: 240px;
    background: var(--bg-white);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 48px;
    left: 0;
    height: calc(100vh - 48px);
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 10;
}

.sidebar-nav {
    padding: var(--space-3) 0;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-7);
    color: var(--gray-700);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    transition: all var(--transition-fast);
}

.sidebar-item:hover {
    background: var(--gray-100);
    color: var(--gray-900);
    text-decoration: none;
}

.sidebar-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: var(--font-weight-semibold);
}

.sidebar-item .icon {
    font-size: var(--font-size-lg);
    width: 20px;
    text-align: center;
}

.sidebar-divider {
    height: 1px;
    background: var(--border-color-light);
    margin: var(--space-4) var(--space-7);
}

/* ----- Main Content ----- */
.main-content {
    flex: 1;
    padding: var(--space-7);
    min-width: 0;
    margin-left: 240px;
}

/* ----- Page Header ----- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-7);
}

.page-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--gray-900);
    line-height: var(--line-height-tight);
}

.page-subtitle {
    font-size: var(--font-size-sm);
    color: var(--gray-600);
    margin-top: var(--space-1);
}

.page-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

/* ----- Breadcrumbs ----- */
.breadcrumb {
    font-size: var(--font-size-xs);
    color: var(--gray-600);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.breadcrumb a {
    color: var(--primary);
}

.breadcrumb-separator {
    color: var(--gray-400);
}

/* ----- Auth Layout ----- */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
}

.auth-card {
    max-width: 400px;
    width: 100%;
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--box-shadow-lg);
    overflow: hidden;
}

.auth-header {
    background: var(--primary);
    color: white;
    padding: var(--space-8);
    text-align: center;
}

.auth-header h1 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    margin-top: var(--space-3);
}

.auth-body {
    padding: var(--space-8);
}

.auth-footer {
    padding: 0 var(--space-8) var(--space-8);
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

/* ----- Detail Layout (two columns) ----- */
.detail-layout {
    display: flex;
    gap: var(--space-5);
    align-items: flex-start;
}

.detail-main {
    flex: 1;
    min-width: 0;
}

.detail-sidebar {
    width: 320px;
    flex-shrink: 0;
}

/* ----- Utilities ----- */
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-primary { color: var(--primary) !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-nowrap { white-space: nowrap; }
.d-flex { display: flex; }
.d-none { display: none; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-5 { gap: var(--space-5); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-7 { margin-bottom: var(--space-7); }
.mt-3 { margin-top: var(--space-3); }
.mt-5 { margin-top: var(--space-5); }
.fw-medium { font-weight: var(--font-weight-medium); }
.fw-semibold { font-weight: var(--font-weight-semibold); }
.w-100 { width: 100%; }

/* ----- Responsive ----- */
@media (max-width: 1279px) {
    .sidebar {
        display: none;
    }
    .main-content {
        margin-left: 0;
        padding: var(--space-4);
        max-width: 100%;
    }
    .detail-layout {
        flex-direction: column;
    }
    .detail-sidebar {
        width: 100%;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }
}

@media (max-width: 640px) {
    .global-search-input,
    .global-search-input:focus {
        width: 160px;
    }
}
