@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #fafafa;
    --text-primary: #000000;
    --text-secondary: #666666;
    --border-color: #e5e5e5;
    --hover-bg: #f5f5f5;
    --accent: #000000;
    --error: #ff3333;
    --success: #000000;
    --sidebar-width: 280px;
}

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

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Layout Core */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Mobile Header (Hidden on Desktop) */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    padding: 0 1.25rem;
    align-items: center;
    justify-content: space-between;
}

.menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-primary);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    padding: 2.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 150;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 3rem 4rem;
    background-color: var(--bg-primary);
    min-width: 0;
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 125;
    backdrop-filter: blur(4px);
}

/* Desktop vs Mobile adjustments */
@media (max-width: 1024px) {
    .main-content {
        padding: 2rem;
    }
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.active {
        display: block;
    }
    .main-content {
        margin-left: 0;
        margin-top: 60px;
        padding: 1.5rem;
    }
}

/* Typography */
h1 { font-size: 1.875rem; font-weight: 800; margin-bottom: 0.5rem; letter-spacing: -0.04em; }
h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.25rem; letter-spacing: -0.01em; }

/* Components */
.card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .card { padding: 1.25rem; border-radius: 12px; }
    h1 { font-size: 1.5rem; }
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary { background: #000; color: #fff; }
.btn-outline { background: transparent; border-color: var(--border-color); color: #000; }

.input, select, textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    background-color: #fff;
    outline: none;
    transition: all 0.2s ease;
}

/* Responsive Grid for Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
}

/* Responsive Table */
.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
}

th {
    padding: 1rem 1.25rem;
    background: var(--bg-secondary);
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
}

td {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9375rem;
}

/* Helper Classes */
.hidden-mobile { @media (max-width: 768px) { display: none; } }
.visible-mobile { display: none; @media (max-width: 768px) { display: block; } }

/* Sidebar Links */
.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 0.375rem;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-link:hover, .sidebar-link.active {
    background: var(--hover-bg);
    color: #000;
}

.sidebar-link.active { font-weight: 700; }

.sidebar-link svg { margin-right: 0.875rem; width: 22px; height: 22px; }

/* Code Search Specific Mobile adjustments */
@media (max-width: 768px) {
    .search-flex {
        flex-direction: column;
    }
    .search-flex button {
        width: 100%;
        height: 3.5rem !important;
    }
}

/* Badge */
.badge {
    padding: 0.4rem 0.8rem;
    border-radius: 30px;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.loading-content {
    animation: fadeIn 0.3s ease-out;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Search Page ─────────────────────────────────────────────────── */
.search-card { padding: 2.5rem; }

.email-iframe {
    width: 100%;
    height: 600px;
    border: none;
    display: block;
}

.result-subject {
    font-size: 1.25rem;
    line-height: 1.3;
    word-break: break-word;
}

.copy-code-box {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.error-card {
    text-align: center;
    padding: 3rem 1.5rem;
}

@media (max-width: 768px) {
    .search-card { padding: 1.25rem; }

    .email-iframe { height: 320px; }

    .result-subject { font-size: 1rem; }

    .copy-code-box { flex-direction: column; align-items: stretch; }
    .copy-code-box button { width: 100% !important; flex: none !important; }

    .error-card { padding: 2rem 1.25rem; }
}

@media (max-width: 480px) {
    .email-iframe { height: 240px; }
}
