/* ============================================================================
   CSS Variables
   ============================================================================ */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --radius-sm: 4px;
}

/* ============================================================================
   Base Styles
   ============================================================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* ============================================================================
   Login Page
   ============================================================================ */
#login-section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

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

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    color: var(--primary-color);
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

#login-form .form-group {
    margin-bottom: 1.25rem;
}

#login-form input {
    padding: 0.875rem 1rem;
}

.btn-full {
    width: 100%;
    padding: 0.875rem 1.5rem;
}

#login-error {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #fef2f2;
    border-radius: var(--radius-sm);
}

/* ============================================================================
   Header
   ============================================================================ */
header {
    margin-bottom: 2rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-content>div {
    text-align: left;
}

header h1 {
    color: var(--primary-color);
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* ============================================================================
   Cards
   ============================================================================ */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.card h4 {
    font-size: 1rem;
    margin: 0;
    color: var(--text-primary);
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ============================================================================
   Buttons
   ============================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
}

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

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #475569;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: #059669;
}

/* ============================================================================
   Logo Styles
   ============================================================================ */
.logo {
    height: 60px;
    margin-bottom: 1.5rem;
}

.header-logo {
    height: 40px;
}

/* ============================================================================
   Tabs
   ============================================================================ */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* .tab-content { default visible } */

/* ============================================================================
   Sub-tabs
   ============================================================================ */
.sub-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.sub-tab-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.sub-tab-btn:hover {
    background: var(--card-bg);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.sub-tab-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* .sub-tab-content { default visible } */

/* ============================================================================
   Collapsible Cards
   ============================================================================ */
.collapsible .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 1rem 1.5rem;
    background: var(--bg-color);
    border-radius: var(--radius) var(--radius) 0 0;
    margin: -1.5rem -1.5rem 1rem -1.5rem;
    transition: background-color 0.2s;
}

.collapsible .card-header:hover {
    background: #e2e8f0;
}

.collapse-icon {
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.collapsible.collapsed .card-body {
    display: none;
}

.collapsible.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

/* ============================================================================
   Toolbar
   ============================================================================ */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.meta-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.company-name {
    font-weight: 600;
    color: var(--text-primary);
}

.ticker-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
}

.period-badge {
    background: var(--secondary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
}

.separator {
    color: var(--border-color);
}

/* ============================================================================
   Statement Container
   ============================================================================ */
.statement-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.statement-content {
    max-height: 500px;
    overflow-y: auto;
}

/* ============================================================================
   Data Tables
   ============================================================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--text-primary);
    position: sticky;
    top: 0;
}

.data-table td.number {
    text-align: right;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
}

.data-table tr:hover {
    background: #f8fafc;
}

.data-table .section-header td {
    background: var(--bg-color);
    font-weight: 600;
    padding-top: 1rem;
}

.data-table .indent-1 td:first-child {
    padding-left: 2rem;
}

.data-table .indent-2 td:first-child {
    padding-left: 3rem;
}

.data-table .indent-3 td:first-child {
    padding-left: 4rem;
}

.table-input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    /* Invisible border by default */
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
    text-align: right;
    font-size: 0.9rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.table-input:hover {
    border-color: var(--border-color);
    background: var(--bg-color);
}

.table-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Click to Edit Styles */
.editable-text-container {
    position: relative;
    cursor: text;
    min-height: 100px;
}

.editable-text-container .view-mode {
    display: block;
    padding: 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.editable-text-container .view-mode:hover {
    background-color: var(--bg-color);
    border-color: var(--border-color);
}

.editable-text-container .edit-mode {
    display: none;
    width: 100%;
    padding: 1rem;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
    border: 1px solid var(--primary-color);
    border-radius: var(--radius-md);
    background-color: white;
    resize: none;
    /* Auto-growth handles this */
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    overflow: hidden;
    /* Hide scrollbar */
}

.editable-text-container.editing .view-mode {
    display: none;
}

.editable-text-container.editing .edit-mode {
    display: block;
}

/* ============================================================================
   Two Column Layout
   ============================================================================ */
.two-column-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .two-column-layout {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   Data Grid (for metrics/ratios)
   ============================================================================ */
.data-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.data-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-color);
    border-radius: var(--radius-sm);
    transition: background-color 0.2s;
}

.data-item:hover {
    background: #e2e8f0;
}

.data-item .label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.data-item .value {
    font-size: 1rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
    color: var(--text-primary);
}

.data-item .value.positive {
    color: var(--success-color);
}

.data-item .value.negative {
    color: var(--danger-color);
}

.data-item .value.neutral {
    color: var(--text-muted);
}

/* Editable Data Items */
.data-item.editable {
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
}

.data-item.editable .label {
    font-size: 0.75rem;
    font-weight: 500;
}

.editable-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
    text-align: right;
    background: var(--card-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.editable-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.editable-input:hover {
    border-color: var(--secondary-color);
}

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

/* ============================================================================
   Key-Value Grid
   ============================================================================ */
.key-value-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0.5rem;
}

.key-value-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-color);
    border-radius: var(--radius-sm);
}

.key-value-item .key {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.key-value-item .value {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* ============================================================================
   JSON Display
   ============================================================================ */
.json-display {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    max-height: 600px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ============================================================================
   Prose Content
   ============================================================================ */
.prose-content {
    line-height: 1.8;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.prose-content p {
    margin-bottom: 1rem;
}

.prose-content h1,
.prose-content h2,
.prose-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

/* ============================================================================
   Loading
   ============================================================================ */
#loading {
    text-align: center;
    padding: 3rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 1s linear infinite;
}

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

/* ============================================================================
   Status Text
   ============================================================================ */
.status-text {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}

.status-text.error {
    color: var(--danger-color);
}

.status-text.success {
    color: var(--success-color);
}

/* ============================================================================
   Utility Classes
   ============================================================================ */
.hidden {
    display: none !important;
}

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

.text-center {
    text-align: center;
}

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .sub-tabs {
        flex-wrap: wrap;
    }
}