:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --border: #d9e0e8;
    --border-soft: #edf1f5;
    --text: #111827;
    --muted: #6b7280;
    --muted-soft: #9aa4b2;
    --blue: #2563eb;
    --blue-soft: #eff6ff;
    --danger: #b42318;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 92px 18px 36px;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

.top-bar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1000;
    min-height: 72px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.brand-area {
    display: flex;
    align-items: center;
    gap: 18px;
    min-width: 0;
}

.brand-home {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    flex: 0 0 auto;
}

.brand-home img {
    width: 58px;
    height: 29px;
    object-fit: contain;
}

.brand-home span {
    font-size: 14px;
    font-weight: 700;
}

.stock-heading {
    min-width: 0;
}

.stock-heading h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.1;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stock-heading h1 span {
    color: #2d3748;
    font-weight: 650;
}

.stock-heading p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex: 0 0 auto;
}

.watch-button {
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: #334155;
    padding: 0 13px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.watch-button:hover,
.watch-button.is-active {
    border-color: #334155;
    color: #111827;
}

.watch-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.search-wrapper {
    position: relative;
    width: min(300px, 26vw);
}

#stock-search-input {
    width: 100%;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: #f8fafc;
    color: var(--text);
    padding: 0 14px;
    font-size: 14px;
    outline: none;
}

#stock-search-input:focus {
    background: #fff;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#stock-search-suggestions {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 2000;
    display: none;
    max-height: 320px;
    overflow: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.12);
}

.suggest-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-soft);
}

.suggest-item:last-child {
    border-bottom: 0;
}

.suggest-item:hover,
.suggest-item.active {
    background: var(--blue-soft);
}

button {
    font: inherit;
}

.btn-primary,
.btn-secondary,
#btnSaveActiveNote {
    height: 38px;
    border-radius: 6px;
    padding: 0 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-primary {
    border: 1px solid var(--blue);
    background: var(--blue);
    color: #fff;
}

.btn-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.btn-secondary {
    border: 1px solid var(--border);
    background: #fff;
    color: #334155;
}

.btn-secondary:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.btn-primary:disabled,
.btn-secondary:disabled,
#btnSaveActiveNote:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.page-shell {
    width: min(1680px, 100%);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 16px;
    align-items: start;
}

.nav-sidebar {
    position: sticky;
    top: 90px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
}

.nav-sidebar-title {
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-sidebar-section + .nav-sidebar-section {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}

.nav-sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--muted-soft);
    font-size: 12px;
}

.nav-empty {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.nav-item {
    display: flex;
    flex-direction: column;
    padding: 6px 8px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text);
    transition: background 0.15s;
}

.nav-item:hover {
    background: var(--blue-soft);
}

.nav-item.is-current {
    background: var(--blue-soft);
    border: 1px solid var(--blue);
    padding: 5px 7px;
}

.nav-item strong {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}

.nav-item span {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.main-content {
    min-width: 0;
}

.action-sidebar {
    position: fixed;
    right: 20px;
    top: 120px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-sidebar .btn-primary,
.action-sidebar .btn-secondary {
    width: 110px;
}

.profile-panel,
.chart-card,
.note-dock {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.profile-panel {
    padding: 18px 20px;
    margin-bottom: 18px;
}

.company-name {
    margin-bottom: 14px;
    color: #334155;
    font-size: 15px;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 14px 22px;
}

.profile-grid label {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 12px;
}

.profile-grid span,
.profile-grid a {
    color: var(--text);
    font-size: 15px;
    text-decoration: none;
}

.profile-grid a {
    color: var(--blue);
}

.analysis-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(430px, 100%), 1fr));
    gap: 16px;
    min-width: 0;
}

.chart-card {
    min-width: 0;
    padding: 14px 14px 10px;
}

.chart-card.is-wide {
    grid-column: 1 / -1;
}

.chart-card.is-active {
    border-color: #b8c4d6;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.06);
}

.chart-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    min-height: 42px;
    margin-bottom: 6px;
}

.chart-card h2 {
    margin: 0;
    font-size: 15px;
    line-height: 1.35;
    font-weight: 700;
    color: #1f2937;
}

.chart-card p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.chart-notice {
    margin: 8px 0;
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #5f6c7b;
    font-size: 12px;
    line-height: 1.5;
}

.balance-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
}

.balance-controls button {
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: #334155;
    padding: 0 9px;
    cursor: pointer;
    font-size: 12px;
}

.balance-controls button:hover:not(:disabled) {
    border-color: var(--blue);
    color: var(--blue);
}

.balance-controls button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.balance-controls span {
    min-width: 82px;
    text-align: center;
    color: #334155;
    font-weight: 600;
}

.balance-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin: 8px 0 2px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.balance-table-section {
    margin-top: 12px;
    border-top: 1px solid var(--border-soft);
    padding-top: 12px;
}

.balance-table-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.balance-table-head h3 {
    margin: 0;
    color: #1f2937;
    font-size: 14px;
}

.balance-table-head span,
.balance-table-empty {
    color: var(--muted);
    font-size: 12px;
}

.balance-table-wrap {
    max-height: 520px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.balance-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.balance-table th,
.balance-table td {
    border-bottom: 1px solid var(--border-soft);
    border-right: 1px solid var(--border-soft);
    padding: 7px 9px;
    white-space: nowrap;
}

.balance-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    color: #334155;
    font-weight: 650;
}

.balance-table th:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 260px;
    max-width: 360px;
    background: #f8fafc;
    color: #334155;
    text-align: left;
    font-weight: 500;
    white-space: normal;
}

.balance-table thead th:first-child {
    z-index: 3;
}

.balance-table td {
    min-width: 128px;
    color: #111827;
    text-align: right;
}

.balance-row-section th,
.balance-row-section td {
    background: #f8fafc;
    color: #1f2937;
    font-weight: 700;
}

.balance-row-total th,
.balance-row-total td {
    color: #111827;
    font-weight: 600;
}

.balance-row-sub th {
    color: #64748b;
    font-weight: 500;
    padding-left: 24px;
}

.balance-row-item th {
    color: #475569;
    font-weight: 500;
    padding-left: 16px;
}

.balance-table .is-current-period {
    background: #eef3f1;
}

.balance-table-section.period-flash .is-current-period {
    animation: balancePeriodFlash 1s ease-out;
}

@keyframes balancePeriodFlash {
    0% { background: #d6e4df; }
    45% { background: #edf5f2; }
    100% { background: #eef3f1; }
}

.stock-chart {
    width: 100%;
    height: 360px;
    min-height: 360px;
}

.note-dock {
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 108px);
    overflow: auto;
    padding: 16px;
}

.note-dock-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.note-dock-head h2 {
    margin: 0;
    font-size: 18px;
}

.note-dock-head p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

#note-save-state {
    color: var(--muted-soft);
    font-size: 12px;
    white-space: nowrap;
}

#note-save-state.is-dirty {
    color: #9a6700;
}

#note-save-state.is-error {
    color: var(--danger);
}

#note-save-state.is-saved {
    color: var(--blue);
}

.note-tabs,
.note-extra-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.note-tabs {
    margin-bottom: 12px;
}

.note-tab {
    min-height: 30px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: #475569;
    padding: 0 10px;
    cursor: pointer;
    font-size: 12px;
}

.note-tab:hover {
    border-color: #b8c4d6;
}

.note-tab.is-active {
    border-color: var(--blue);
    color: var(--blue);
    background: var(--blue-soft);
}

.note-editor-panel {
    border-top: 1px solid var(--border-soft);
    padding-top: 12px;
}

#active-note-label {
    display: block;
    color: #1f2937;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
}

#active-note-editor {
    width: 100%;
    min-height: 260px;
    max-height: 48vh;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    color: var(--text);
    background: #fff;
    font: inherit;
    font-size: 14px;
    line-height: 1.7;
}

#active-note-editor:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.note-meta-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.note-meta-line span {
    min-width: 0;
    color: var(--muted);
    font-size: 12px;
}

.note-meta-line b {
    font-weight: 500;
}

#btnSaveActiveNote {
    flex: 0 0 auto;
    border: 1px solid var(--blue);
    background: var(--blue);
    color: #fff;
}

#btnSaveActiveNote:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.note-extra {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}

.note-extra-title {
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

@media (max-width: 1320px) {
    .analysis-workspace {
        grid-template-columns: minmax(0, 1fr) 330px;
    }

    .stock-chart {
        height: 340px;
        min-height: 340px;
    }
}

@media (max-width: 1080px) {
    body {
        padding-top: 144px;
    }

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

    .toolbar-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .search-wrapper {
        width: min(420px, 100%);
        flex: 1 1 260px;
    }

    .page-shell {
        grid-template-columns: 1fr;
    }

    .nav-sidebar {
        position: static;
        max-height: none;
    }

    .analysis-workspace {
        display: flex;
        flex-direction: column;
    }

    .note-dock {
        position: static;
        order: -1;
        width: 100%;
        max-height: none;
    }
}

@media (max-width: 720px) {
    body {
        padding: 0 10px 96px;
    }

    .top-bar {
        position: static;
        margin: 0 -10px 12px;
        padding: 10px 12px;
    }

    .brand-area {
        width: 100%;
        gap: 12px;
    }

    .brand-home span {
        display: none;
    }

    .stock-heading h1 {
        font-size: 22px;
    }

    .toolbar-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .search-wrapper {
        grid-column: 1 / -1;
        width: 100%;
        flex: none;
    }

    .action-sidebar {
        position: fixed;
        right: 10px;
        left: 10px;
        top: auto;
        bottom: 10px;
        z-index: 1100;
        flex-direction: row;
        justify-content: center;
        gap: 10px;
    }

    .action-sidebar .btn-primary,
    .action-sidebar .btn-secondary {
        flex: 1;
        max-width: 180px;
    }

    .profile-grid {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .profile-panel,
    .chart-card,
    .note-dock {
        padding: 14px;
    }

    .stock-chart {
        height: 320px;
        min-height: 320px;
    }

    .balance-table-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }

    .balance-table-wrap {
        max-height: 560px;
    }

    .balance-table th:first-child {
        min-width: 190px;
        max-width: 220px;
    }

    .balance-table td {
        min-width: 116px;
    }

    .note-meta-line {
        align-items: stretch;
        flex-direction: column;
    }

    #btnSaveActiveNote {
        width: 100%;
    }
}
