:root {
    --bg-color: #020617;
    --panel-bg: rgba(15, 23, 42, 0.65);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --primary-light: #00d2ff;
    --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --blob-1: #3b82f6;
    --blob-2: #8b5cf6;
    --glass-bg: rgba(30, 41, 59, 0.4);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body.app-history-ready {
    --history-rail-width: 72px;
    --history-panel-width: 316px;
    --history-top: 70px;
}

/* Background */
.background-elements {
    position: fixed; top: 0; left: 0;
    width: 100vw; height: 100vh; z-index: -1; overflow: hidden;
}

.blob {
    position: absolute; filter: blur(120px); opacity: 0.14;
    border-radius: 50%; animation: float 20s infinite ease-in-out alternate;
}
.blob-1 { width: 500px; height: 500px; background: var(--blob-1); top: -100px; left: -100px; }
.blob-2 { width: 400px; height: 400px; background: var(--blob-2); bottom: -50px; right: -50px; animation-delay: -10s; }

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(80px, 40px) scale(1.15); }
}

/* Glass Panel */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(24px) saturate(200%);
    -webkit-backdrop-filter: blur(24px) saturate(200%);
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

.glass-panel:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 20px 50px -15px rgba(0, 0, 0, 0.6);
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Top Bar styles are unified and managed in navbar.css and mobile.css */


.nav-item {
    position: relative;
    display: inline-block;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    border-radius: 8px;
    transition: all 0.25s ease;
    cursor: pointer;
    user-select: none;
}

.nav-link:hover, .nav-item:hover > .nav-link {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.nav-link.active {
    color: #bfdbfe;
    background: rgba(37, 99, 235, 0.18);
}

/* Dropdown Content - 확실한 숨김 처리 및 자석 브릿지 추가 */
.dropdown-content {
    position: absolute;
    top: 90%; /* 메뉴 바와 살짝 겹치게 하여 마우스 이동 시 끊김 방지 */
    left: 50%;
    transform: translateX(-50%) translateY(15px);
    width: 260px;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 14px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), visibility 0.3s;
    box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.8);
    z-index: 10001; /* 다른 UI 요소보다 확실히 위에 표시 */
}

/* 마우스 이동 시 연결이 끊기지 않도록 투명 자석 브릿지 (Bridge) */
.dropdown-content::before {
    content: '';
    position: absolute;
    top: -30px; /* 위쪽 영역을 넉넉하게 채워 호버 유지 */
    left: 0;
    right: 0;
    height: 40px;
    background: transparent;
}

.nav-item:hover .dropdown-content {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(10px);
}

.dropdown-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 0.88rem;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.dropdown-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.dropdown-link i {
    width: 20px;
    font-size: 1.1rem;
    color: var(--primary-light);
}

.dropdown-header {
    padding: 6px 14px 10px;
    font-size: 0.7rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.dropdown-link div span {
    display: block;
    font-weight: 600;
    margin-bottom: 2px;
}

.dropdown-link div small {
    display: block;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    font-weight: 400;
}

/* --- Premium Tabs (index.html 전용) --- */
.nav-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.03);
    padding: 6px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    width: fit-content;
}

.nav-tabs .tab {
    padding: 10px 24px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-tabs .tab:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.nav-tabs .tab.active {
    background: var(--primary-light);
    color: #000;
    box-shadow: 0 4px 15px rgba(0, 210, 255, 0.3);
}

.user-badge {
    display: flex; align-items: center; gap: 0.5rem;
    background: rgba(255,255,255,0.05);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.user-badge i { color: var(--accent-color); }

.icon-btn {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; font-size: 1rem; padding: 0.4rem 0.6rem;
    border-radius: 8px; transition: all 0.2s;
}
.icon-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.1); }

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.stat-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.2rem;
    transition: transform 0.3s, box-shadow 0.3s;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-info {
    display: flex; flex-direction: column;
}

.stat-value {
    font-size: 1.6rem; font-weight: 800;
    letter-spacing: -0.5px;
}

.stat-label {
    font-size: 0.75rem; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 1px;
    margin-top: 0.2rem;
    font-weight: 500;
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
}

.chart-card { padding: 1.5rem; }

.chart-header {
    margin-bottom: 1rem;
}

.chart-header h2 {
    font-size: 1rem; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.5px;
    display: flex; align-items: center; gap: 0.5rem;
    margin: 0;
}

.chart-body {
    position: relative;
    height: 280px;
}

.chart-body canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Users Table */
.users-section {
    padding: 1.5rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
}

.section-header h2 {
    font-size: 1rem; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.5px;
    display: flex; align-items: center; gap: 0.5rem;
    margin: 0;
}

.add-user-btn {
    background: linear-gradient(135deg, var(--success-color), #059669);
    color: white; border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    font-family: inherit; font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all 0.3s;
    display: flex; align-items: center; gap: 0.4rem;
}
.add-user-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.table-wrapper {
    overflow-x: auto;
}

.table-wrapper table {
    width: 100%;
    border-collapse: collapse;
}

.table-wrapper thead th {
    text-align: left;
    padding: 0.8rem 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    position: sticky;
    top: 0;
    background: rgba(15, 23, 42, 0.95);
    z-index: 10;
}

.table-wrapper tbody td {
    padding: 0.9rem 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text-primary);
}

.table-wrapper tbody tr {
    transition: background 0.2s;
}

.table-wrapper tbody tr:hover {
    background: rgba(59, 130, 246, 0.06);
}

.empty-row {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem !important;
}

.tier-badge {
    display: inline-block;
    padding: 0.2rem 0.7rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.tier-try,
.tier-free { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
.tier-basic { background: rgba(24, 95, 75, 0.15); color: #185f4b; }
.tier-pro { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.tier-ultra,
.tier-enterprise { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }
.tier-admin { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-card {
    width: 100%; max-width: 420px;
    padding: 2rem;
    animation: slideUp 0.3s ease-out;
}

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    font-size: 1.1rem; font-weight: 700;
    display: flex; align-items: center; gap: 0.5rem;
}

.modal-close { font-size: 1.2rem; }

.modal-input-group {
    margin-bottom: 1rem;
}

.modal-input-group label {
    display: block;
    font-size: 0.8rem; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.4rem;
}

.modal-input-group input,
.modal-input-group select {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit; font-size: 0.9rem;
    outline: none; transition: border-color 0.3s;
}

.modal-input-group input:focus,
.modal-input-group select:focus {
    border-color: var(--accent-color);
}

.modal-input-group select option {
    background: #1e293b; color: var(--text-primary);
}

.login-btn {
    width: 100%;
    padding: 0.9rem;
    background: linear-gradient(135deg, var(--accent-color), var(--blob-2));
    color: white; border: none;
    border-radius: 12px;
    font-family: inherit; font-size: 0.95rem; font-weight: 600;
    cursor: pointer; transition: all 0.3s;
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99,102,241,0.4);
}

.error-msg {
    margin-top: 1rem; padding: 0.7rem 1rem;
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: 10px;
    color: #fca5a5; font-size: 0.85rem;
    display: flex; align-items: center; gap: 0.5rem;
}

/* Analysis Dashboard */
.hidden { display: none !important; }

#company-header {
    padding: 1.4rem 1.6rem;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
}

#company-header h1 {
    font-size: 1.8rem;
    line-height: 1.2;
    margin-bottom: 0.8rem;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.14);
    border: 1px solid rgba(96, 165, 250, 0.24);
    color: #bfdbfe;
    font-size: 0.78rem;
    font-weight: 600;
}

.dashboard-controls {
    max-width: 1500px;
    margin: 18px auto 0;
    padding: 0 20px;
    display: grid;
    grid-template-columns: minmax(240px, auto) 1fr;
    align-items: start;
    gap: 16px;
}

.dashboard-controls .nav-tabs {
    margin-bottom: 0;
    max-width: 100%;
    overflow-x: auto;
}

.period-panel {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(2, 6, 23, 0.68);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
}

.period-mode-group {
    display: inline-flex;
    gap: 6px;
    padding: 4px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
}

.chart-view-group {
    display: none;
    gap: 6px;
    padding: 4px;
    background: rgba(15, 23, 42, 0.62);
    border: 1px solid rgba(102, 227, 255, 0.16);
    border-radius: 12px;
}

.chart-view-group .segmented-option span {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.78rem;
}

.segmented-option {
    cursor: pointer;
    user-select: none;
}

.segmented-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented-option span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 9px;
    color: rgba(255,255,255,0.62);
    font-size: 0.85rem;
    font-weight: 700;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.segmented-option input:checked + span {
    color: #04111f;
    background: #66e3ff;
    box-shadow: 0 8px 22px rgba(0, 210, 255, 0.24);
}

.period-selects {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
}

.period-select-wrapper {
    display: flex;
    align-items: center;
    gap: 7px;
}

.period-select-wrapper label {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
}

.period-select-wrapper select {
    min-height: 34px;
    background: rgba(0,0,0,0.45);
    color: white;
    border: 1px solid rgba(102, 227, 255, 0.45);
    padding: 0 10px;
    border-radius: 9px;
    cursor: pointer;
    outline: none;
    font-family: inherit;
    font-size: 0.85rem;
}

.period-select-wrapper select option {
    background: #111827;
    color: white;
}

.latest-period-badge {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.28);
    color: #a7f3d0;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
}

.period-helper-note {
    flex-basis: 100%;
    text-align: right;
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.4;
}

.loading-copy,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 220px;
    color: var(--text-secondary);
    text-align: center;
}

.loading-copy strong,
.empty-state strong {
    color: var(--text-primary);
    font-size: 1rem;
}

.empty-state i {
    color: var(--warning-color);
    font-size: 1.8rem;
}

.empty-state button {
    margin-top: 0.6rem;
    padding: 0.65rem 1rem;
    background: #66e3ff;
    border: none;
    border-radius: 9px;
    color: #06111f;
    font-weight: 800;
    cursor: pointer;
}

.metric-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.metric-card {
    min-height: 104px;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.58);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
}

.metric-card-ratio {
    background: rgba(8, 47, 73, 0.42);
    border-color: rgba(56, 189, 248, 0.16);
}

.metric-card span,
.metric-card small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 700;
}

.metric-card strong {
    display: block;
    margin: 0.45rem 0;
    font-size: 1.35rem;
    line-height: 1.1;
    word-break: break-word;
}

#main-content {
    display: grid;
    gap: 18px;
}

.charts-grid {
    width: 100%;
}

.charts-grid .glass-panel {
    padding: 1rem;
    border-radius: 16px;
}

.chart-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
}

.chart-metric-select {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chart-metric-select span {
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 800;
    white-space: nowrap;
}

.chart-metric-select select {
    min-height: 34px;
    min-width: 132px;
    padding: 0 10px;
    border-radius: 9px;
    border: 1px solid rgba(102, 227, 255, 0.36);
    background: rgba(2, 6, 23, 0.82);
    color: var(--text-primary);
    font-family: inherit;
    font-weight: 800;
    outline: none;
}

.chart-metric-select option {
    background: #111827;
    color: white;
}

.charts-grid .glass-panel:hover,
.account-groups:hover {
    transform: none;
}

.account-groups {
    padding: 1rem;
    background: rgba(15, 23, 42, 0.56);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
}

.account-groups-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.account-groups-title strong {
    display: block;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.account-groups-title span {
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.45;
}

.account-groups {
    display: grid;
    gap: 10px;
}

.account-group {
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    background: rgba(2, 6, 23, 0.34);
}

.account-group-header {
    width: 100%;
    min-height: 68px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto auto;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.group-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: rgba(102, 227, 255, 0.12);
    color: #66e3ff;
}

.group-copy {
    min-width: 0;
}

.group-copy strong,
.group-copy small {
    display: block;
}

.group-copy strong {
    font-size: 0.98rem;
    margin-bottom: 0.25rem;
}

.group-copy small,
.group-meta {
    color: var(--text-secondary);
    font-size: 0.76rem;
}

.group-meta {
    white-space: nowrap;
}

.group-total {
    min-width: 96px;
    text-align: right;
    font-weight: 900;
    color: #d9f99d;
}

.group-chevron {
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.account-group.open .group-chevron {
    transform: rotate(180deg);
}

.account-group-body {
    display: none;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.account-group.open .account-group-body {
    display: block;
}

.subgroup-shell {
    padding: 0.9rem;
}

.subgroup-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.subgroup-tab {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.45rem 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.62);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-weight: 800;
    transition: border-color 0.18s, background 0.18s, color 0.18s;
}

.subgroup-tab small {
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 800;
}

.subgroup-tab.active {
    background: rgba(102, 227, 255, 0.16);
    border-color: rgba(102, 227, 255, 0.48);
    color: #a5f3fc;
    box-shadow: inset 0 0 0 1px rgba(102, 227, 255, 0.12);
}

.subgroup-panel {
    display: none;
    margin-top: 0.85rem;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    overflow: hidden;
    background: rgba(2, 6, 23, 0.28);
}

.subgroup-panel.active {
    display: block;
}

.subgroup-panel-title {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 0.85rem;
    background: rgba(15, 23, 42, 0.7);
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.subgroup-panel-title strong {
    font-size: 0.88rem;
}

.subgroup-panel-title span {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 800;
}

.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.naver-style-table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

.analysis-table th,
.analysis-table td {
    padding: 0.78rem 0.9rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.84rem;
    vertical-align: middle;
}

.analysis-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(15, 23, 42, 0.96);
    color: var(--text-secondary);
    text-align: right;
}

.analysis-table th:first-child,
.analysis-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 230px;
    text-align: left;
    background: rgba(15, 23, 42, 0.96);
    font-weight: 700;
}

.analysis-table td {
    text-align: right;
}

.analysis-table td.missing-value-cell {
    color: rgba(255, 255, 255, 0.42);
}

.analysis-table tr:hover td {
    background: rgba(59, 130, 246, 0.08);
}

.app-history-toggle {
    position: fixed;
    left: 16px;
    top: calc(var(--history-top, 70px) + 14px);
    z-index: 980;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.94);
    color: #cbd5e1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 12px 32px rgba(2, 6, 23, 0.36);
}

.app-history-toggle:hover {
    color: #fff;
    border-color: rgba(96, 165, 250, 0.34);
    background: rgba(30, 41, 59, 0.96);
}

.app-history-toggle span {
    display: none;
}

.app-history-drawer {
    position: fixed;
    top: var(--history-top, 70px);
    left: 0;
    z-index: 970;
    width: var(--history-panel-width, 316px);
    height: calc(100vh - var(--history-top, 70px));
    background: rgba(8, 13, 24, 0.98);
    border-right: 1px solid rgba(148, 163, 184, 0.13);
    box-shadow: 18px 0 45px rgba(2, 6, 23, 0.26);
    transform: translateX(calc(-1 * var(--history-panel-width, 316px)));
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
}

body.app-history-open .app-history-drawer {
    transform: translateX(0);
}

.app-history-scrim {
    display: none;
    position: fixed;
    inset: var(--history-top, 70px) 0 0 0;
    z-index: 960;
    border: 0;
    background: rgba(2, 6, 23, 0.48);
    cursor: pointer;
}

body.app-history-open .app-history-toggle {
    opacity: 0;
    pointer-events: none;
}

.app-history-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1rem 0.85rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.11);
}

.app-history-kicker {
    display: block;
    margin-bottom: 0.38rem;
    color: #60a5fa;
    font-size: 0.68rem;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0;
}

.app-history-title {
    margin: 0 0 0.28rem;
    color: #f8fafc;
    font-size: 1rem;
    font-weight: 850;
}

.app-history-desc {
    margin: 0;
    color: #94a3b8;
    font-size: 0.76rem;
    line-height: 1.42;
}

.app-history-close {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.6);
    color: #cbd5e1;
    cursor: pointer;
}

.app-history-close:hover {
    color: #fff;
    border-color: rgba(96, 165, 250, 0.34);
}

.app-history-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.55rem;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.app-history-search {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 8px;
    background: rgba(2, 6, 23, 0.36);
    color: #94a3b8;
}

.app-history-search input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: #f8fafc;
    font: inherit;
    font-size: 0.8rem;
}

.app-history-new {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 8px;
    background: #2563eb;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.app-history-new:hover {
    background: #1d4ed8;
}

.app-history-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0.7rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.app-history-list::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.app-history-state {
    padding: 1.2rem 0.85rem;
    color: #94a3b8;
    font-size: 0.8rem;
    line-height: 1.5;
}

.app-history-date-group {
    margin: 0.9rem 0 0.42rem;
    padding: 0 0.18rem;
    color: #60a5fa;
    font-size: 0.72rem;
    font-weight: 850;
}

.app-history-date-group:first-child {
    margin-top: 0.15rem;
}

.app-history-item {
    display: block;
    width: 100%;
    position: relative;
    padding: 0.78rem;
    border: 1px dashed rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.36);
    color: inherit;
    cursor: pointer;
    margin-bottom: 0.65rem;
}

.app-history-item:hover,
.app-history-item:focus-visible {
    outline: none;
    background: rgba(30, 41, 59, 0.62);
    border-color: rgba(96, 165, 250, 0.48);
    border-style: solid;
}

.app-history-item-title-row {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
}

.app-history-item-title {
    margin: 0 0 0.42rem;
    min-width: 0;
    flex: 1;
    color: #f8fafc;
    font-size: 0.83rem;
    font-weight: 800;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-history-item-summary {
    margin: 0;
    color: #94a3b8;
    font-size: 0.74rem;
    line-height: 1.38;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-history-item-actions {
    display: none;
    position: absolute;
    top: 32px;
    right: 0;
    z-index: 8;
    min-width: 148px;
    padding: 0.35rem;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 14px 32px rgba(2, 6, 23, 0.42);
}

.app-history-menu {
    position: relative;
    flex: 0 0 auto;
}

.app-history-menu.open .app-history-item-actions {
    display: grid;
    gap: 0.25rem;
}

.app-history-menu-button {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 7px;
    background: rgba(2, 6, 23, 0.22);
    color: #94a3b8;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-history-menu-button:hover,
.app-history-menu-button:focus-visible,
.app-history-menu.open .app-history-menu-button {
    outline: none;
    color: #f8fafc;
    border-color: rgba(96, 165, 250, 0.36);
    background: rgba(37, 99, 235, 0.16);
}

.app-history-menu-item {
    width: 100%;
    min-height: 34px;
    padding: 0 0.65rem;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.55rem;
    cursor: pointer;
    font: inherit;
    font-size: 0.76rem;
    font-weight: 800;
    text-align: left;
}

.app-history-menu-item i {
    width: 14px;
    text-align: center;
}

.app-history-menu-item:hover,
.app-history-menu-item:focus-visible {
    outline: none;
    color: #fff;
    background: rgba(37, 99, 235, 0.16);
}

.app-history-menu-item.primary {
    color: #bfdbfe;
}

.app-history-menu-item.danger {
    color: #fca5a5;
}

.app-history-menu-item.danger:hover,
.app-history-menu-item.danger:focus-visible {
    background: rgba(127, 29, 29, 0.22);
}

.app-history-action {
    min-width: 0;
    min-height: 32px;
    padding: 0 0.55rem;
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 8px;
    background: rgba(2, 6, 23, 0.28);
    color: #cbd5e1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.38rem;
    cursor: pointer;
    font: inherit;
    font-size: 0.72rem;
    font-weight: 800;
}

.app-history-action span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-history-action:hover,
.app-history-action:focus-visible {
    outline: none;
    color: #fff;
    border-color: rgba(96, 165, 250, 0.42);
    background: rgba(37, 99, 235, 0.18);
}

.app-history-action.primary {
    background: rgba(37, 99, 235, 0.28);
    border-color: rgba(96, 165, 250, 0.32);
    color: #dbeafe;
}

.app-history-action.danger {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.18);
}

.app-history-action.danger:hover,
.app-history-action.danger:focus-visible {
    background: rgba(127, 29, 29, 0.2);
    border-color: rgba(248, 113, 113, 0.38);
}

.app-history-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.2rem;
    background: rgba(2, 6, 23, 0.62);
}

.app-history-modal.open {
    display: flex;
}

.app-history-modal-card {
    width: min(820px, 100%);
    max-height: min(82vh, 820px);
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 24px 80px rgba(2, 6, 23, 0.55);
}

.app-history-modal-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.app-history-modal-head h2 {
    margin: 0;
    color: #f8fafc;
    font-size: 1rem;
    font-weight: 850;
}

.app-history-modal-close {
    width: 34px;
    height: 34px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 8px;
    background: rgba(2, 6, 23, 0.28);
    color: #cbd5e1;
    cursor: pointer;
}

.app-history-modal-body {
    overflow: auto;
    padding: 1rem 1.15rem 1.15rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.app-history-modal-body::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.app-history-modal-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.app-history-modal-meta span {
    padding: 0.28rem 0.55rem;
    border-radius: 7px;
    background: rgba(37, 99, 235, 0.14);
    color: #bfdbfe;
    font-size: 0.72rem;
    font-weight: 800;
}

.app-history-modal-section {
    margin-top: 1rem;
}

.app-history-modal-section h3 {
    margin: 0 0 0.55rem;
    color: #93c5fd;
    font-size: 0.86rem;
    font-weight: 850;
}

.app-history-modal-section p,
.app-history-modal-section pre {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.82rem;
    line-height: 1.62;
}

.app-history-modal-section pre {
    white-space: pre-wrap;
    padding: 0.85rem;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(2, 6, 23, 0.32);
    max-height: 38vh;
    overflow: auto;
    scrollbar-width: none;
}

.app-history-modal-section pre::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.app-history-modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.app-history-foot {
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.app-history-foot a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 800;
}

.app-history-foot a:hover {
    color: #fff;
}

@media (min-width: 1025px) {
    body.app-history-ready .container,
    body.app-history-ready .dashboard-hero,
    body.app-history-ready .dashboard-controls,
    body.app-history-ready > main:not(.chat-layout),
    body.app-history-ready .chat-layout {
        transition: margin-left 0.22s ease, width 0.22s ease, max-width 0.22s ease;
    }

    body.app-history-open .container,
    body.app-history-open .dashboard-hero,
    body.app-history-open .dashboard-controls {
        width: calc(100vw - var(--history-panel-width, 316px) - 56px);
        max-width: 1440px;
        margin-left: calc(var(--history-panel-width, 316px) + 32px);
        margin-right: 24px;
    }

    body.app-history-open > main:not(.chat-layout) {
        width: calc(100vw - var(--history-panel-width, 316px) - 56px);
        margin-left: calc(var(--history-panel-width, 316px) + 32px);
        margin-right: 24px;
    }

    body.app-history-open .chat-layout {
        width: min(1000px, calc(100vw - var(--history-panel-width, 316px) - 72px));
        margin-left: calc(var(--history-panel-width, 316px) + 32px);
        margin-right: 24px;
    }
}

@media (max-width: 1024px) {
    body.app-history-ready {
        --history-panel-width: min(88vw, 340px);
    }

    .app-history-toggle {
        top: auto;
        left: 16px;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    }

    .app-history-drawer {
        width: var(--history-panel-width);
        transform: translateX(-100%);
        box-shadow: 18px 0 48px rgba(2, 6, 23, 0.55);
    }

    body.app-history-open .app-history-scrim {
        display: block;
    }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 1024px) {
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
    .dashboard-controls { grid-template-columns: 1fr; }
    .period-panel { justify-content: flex-start; }
    .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .summary-cards { grid-template-columns: 1fr; }
    .top-nav { display: none; }
    .dashboard-controls { padding: 0 12px; }
    .period-mode-group { width: 100%; overflow-x: auto; }
    .chart-view-group { width: 100%; overflow-x: auto; }
    .period-helper-note { text-align: left; }
    .metric-strip { grid-template-columns: 1fr; }
    .account-groups-title { flex-direction: column; }
    .account-group-header {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }
    .group-meta,
    .group-total {
        display: none;
    }
}
