/* ── Theme variables ───────────────────────────────────── */
:root {
    --port-sidebar-bg:      #1e2a38;
    --port-main-bg:         #f4f6f8;
    --port-surface:         #ffffff;
    --port-surface-raised:  #f8f9fa;
    --port-border:          #e5e9ef;
    --port-border-subtle:   #f0f2f4;
    --port-text-primary:    #1e2a38;
    --port-income-top-bg:   #fff9e6;
    --port-income-good-bg:  #f0fbf4;
    --port-income-value:    #1a7a4a;
    --port-ticker-link:     #1e2a38;
    --port-tx-buy-bg:       #f0fbf4;
    --port-tx-sell-bg:      #fff9e6;
}

[data-bs-theme="dark"] {
    --port-sidebar-bg:      #141f2d;
    --port-main-bg:         #0f1923;
    --port-surface:         #1a2535;
    --port-surface-raised:  #1e2d40;
    --port-border:          #2d3f52;
    --port-border-subtle:   #243040;
    --port-text-primary:    #e2e8f0;
    --port-income-top-bg:   #2d2108;
    --port-income-good-bg:  #0d2318;
    --port-income-value:    #4ade80;
    --port-ticker-link:     #60a5fa;
    --port-tx-buy-bg:       #0d2318;
    --port-tx-sell-bg:      #2d2108;
}

/* ── Base ─────────────────────────────────────────────── */
html {
    font-size: 14px;
    height: 100%;
}

@media (min-width: 768px) {
    html { font-size: 16px; }
}

/* Samsung Fold outer screen */
@media (max-width: 320px) {
    html { font-size: 13px; }
}

body {
    height: 100%;
    overflow: hidden;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem var(--port-surface), 0 0 0 0.25rem #258cfb;
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* ── Layout root ─────────────────────────────────────── */
.layout-root {
    display: flex;
    height: 100vh;        /* fallback for older browsers */
    height: 100dvh;       /* adjusts for mobile browser chrome showing/hiding */
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────── */
.portfolio-sidebar {
    background-color: var(--port-sidebar-bg);
    color: #fff;
    width: 220px;
    min-width: 220px;
    flex-shrink: 0;
}

.sidebar-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.25rem 1rem;
}

.sidebar-subtitle {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 2px;
    letter-spacing: 0.03em;
}

.sidebar-nav {
    padding-top: 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 1.1rem;
    color: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    font-size: 0.875rem;
    border-left: 3px solid transparent;
    transition: color 0.15s ease, background-color 0.15s ease;
    white-space: nowrap;
}

.sidebar-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.07);
    text-decoration: none;
}

.sidebar-link.active {
    color: #fff;
    background-color: rgba(52, 152, 219, 0.18);
    border-left-color: #3498db;
}

.sidebar-icon {
    flex-shrink: 0;
    opacity: 0.75;
}

.sidebar-link.active .sidebar-icon,
.sidebar-link:hover .sidebar-icon {
    opacity: 1;
}

/* ── Main wrapper ────────────────────────────────────── */
.main-wrapper {
    flex: 1 1 0;
    min-width: 0;
    background-color: var(--port-main-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
    height: 56px;
    min-height: 56px;
    background-color: var(--port-surface);
    border-bottom: 1px solid var(--port-border);
    flex-shrink: 0;
}

/* ── Page content ────────────────────────────────────── */
.page-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* smooth momentum scroll on iOS */
}

/* ── Page headings ───────────────────────────────────── */
.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--port-text-primary);
    margin-bottom: 1.25rem;
}

/* ── Cards ───────────────────────────────────────────── */
.stat-card {
    background: var(--port-surface);
    border: 1px solid var(--port-border);
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    text-align:center;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--bs-secondary-color);
    margin-bottom: 0.15rem;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--port-text-primary);
}

/* ── Tables ──────────────────────────────────────────── */
.table-card {
    background: var(--port-surface);
    border: 1px solid var(--port-border);
    border-radius: 0.5rem;
    overflow: hidden;
}

/* ── Stocks table ────────────────────────────────────── */
.stocks-table-wrap {
    border-radius: 0 0 0.5rem 0.5rem;
    border-top: none;
}

.stocks-table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bs-secondary-color);
    font-weight: 600;
    padding: 0.55rem 0.6rem;
    white-space: nowrap;
    background: var(--port-surface-raised);
    border-bottom: 1px solid var(--port-border);
}

.stocks-table td {
    padding: 0.4rem 0.6rem;
    vertical-align: middle;
    font-size: 0.825rem;
    white-space: nowrap;
    border-bottom: 1px solid var(--port-border-subtle);
}

.stocks-table tr:last-child td { border-bottom: none; }

/* Sticky action column (Sell button) */
.stocks-table th.col-action,
.stocks-table td.col-action {
    position: sticky;
    right: 0;
    background: inherit;
    z-index: 1;
    box-shadow: -2px 0 4px rgba(0, 0, 0, 0.06);
}

.stocks-table th.col-action { background: var(--port-surface-raised); }
.income-top  td.col-action  { background: var(--port-income-top-bg); }
.income-good td.col-action  { background: var(--port-income-good-bg); }

.ticker-link { color: var(--port-ticker-link); }
.ticker-link:hover { color: #3498db; }

/* Income highlight rows */
.income-top  { background-color: var(--port-income-top-bg); }
.income-good { background-color: var(--port-income-good-bg); }
.income-value { color: var(--port-income-value); }

.btn-xs {
    font-size: 0.7rem;
    padding: 2px 8px;
    line-height: 1.4;
}

/* ── Accounts inline editing ─────────────────────────── */
.accounts-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary-color);
    font-weight: 600;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--port-border);
    background: var(--port-surface-raised);
}

.accounts-table td {
    padding: 0.35rem 0.5rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--port-border-subtle);
}

.accounts-table tfoot td {
    padding: 0.6rem 0.75rem;
    border-bottom: none;
    background: var(--port-surface-raised);
    font-size: 0.875rem;
}

.cell-input {
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    padding: 3px 6px;
    width: 100%;
    font-size: 0.875rem;
    transition: border-color 0.15s, background-color 0.15s;
    min-width: 80px;
}

.cell-input:hover {
    border-color: var(--port-border);
    background-color: var(--port-surface);
}

.cell-input:focus {
    border-color: #3498db;
    background-color: var(--port-surface);
    outline: none;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

.cell-select {
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    padding: 3px 6px;
    font-size: 0.875rem;
    width: 100%;
    transition: border-color 0.15s, background-color 0.15s;
    cursor: pointer;
    min-width: 120px;
}

.cell-select:hover, .cell-select:focus {
    border-color: var(--port-border);
    background-color: var(--port-surface);
    outline: none;
}

.btn-delete {
    font-size: 1.1rem;
    line-height: 1;
    opacity: 0.35;
    transition: opacity 0.15s;
}

.btn-delete:hover { opacity: 1; }

.tracking-row { font-style: italic; color: var(--bs-secondary-color); }
.tracking-row .cell-input, .tracking-row .cell-select { color: var(--bs-secondary-color); }

.totals-row td { font-size: 0.875rem; }

.total-highlight {
    background-color: #b8860b;
    color: #111;
    padding: 2px 4px;
}
[data-bs-theme="dark"] .total-highlight {
    background-color: #b8860b;
    color: #111;
}

.pending-total-row {
    background-color: var(--bs-secondary-bg);
    color: #333;
}
[data-bs-theme="dark"] .pending-total-row {
    background-color: var(--bs-secondary-bg);
    color: #333;
}
.pending-total-label { color: #555; }

/* ── Dashboard ───────────────────────────────────────── */
.dash-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.dash-stats .stat-card {
    flex: 1 1 140px;
    min-width: 130px;
}

.stat-sub {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--bs-secondary-color);
    margin-left: 0.2rem;
}

/* ── Detail page ─────────────────────────────────────── */
.detail-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.detail-stat {
    background: var(--port-surface);
    border: 1px solid var(--port-border);
    border-radius: 0.5rem;
    padding: 0.6rem 1rem;
    min-width: 110px;
}

.detail-card {
    background: var(--port-surface);
    border: 1px solid var(--port-border);
    border-radius: 0.5rem;
    overflow: hidden;
}

.detail-card-header {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary-color);
    padding: 0.6rem 0.85rem;
    background: var(--port-surface-raised);
    border-bottom: 1px solid var(--port-border);
}

.detail-table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bs-secondary-color);
    font-weight: 600;
    padding: 0.45rem 0.6rem;
    background: var(--port-surface-raised);
    border-bottom: 1px solid var(--port-border);
    white-space: nowrap;
}

.detail-table td {
    padding: 0.35rem 0.6rem;
    vertical-align: middle;
    font-size: 0.825rem;
    white-space: nowrap;
    border-bottom: 1px solid var(--port-border-subtle);
}

.detail-table tr:last-child td { border-bottom: none; }

.tx-buy  td { background-color: var(--port-tx-buy-bg); }
.tx-sell td { background-color: var(--port-tx-sell-bg); }

.note-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--port-border-subtle);
}

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

.note-content {
    font-size: 0.875rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.btn-delete-sm {
    font-size: 1rem;
    line-height: 1;
    opacity: 0.4;
    transition: opacity 0.15s;
}

.btn-delete-sm:hover { opacity: 1; }

/* ── Drag-and-drop ───────────────────────────────────── */
.drag-handle {
    cursor: grab;
    color: var(--bs-secondary-color);
    font-size: 0.75rem;
    user-select: none;
}
.drag-handle:active { cursor: grabbing; }
.dragging-row {
    opacity: 0.5;
    background-color: var(--port-surface-raised);
}

/* ── News items ──────────────────────────────────────── */
.news-item {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--port-border-subtle);
    font-size: 0.825rem;
}

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

.news-source {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bs-secondary-color);
}

.news-date {
    font-size: 0.7rem;
    color: var(--bs-secondary-color);
}

.news-headline {
    font-weight: 600;
    color: var(--port-text-primary);
    margin-bottom: 0.2rem;
    line-height: 1.35;
}

.news-summary {
    color: var(--bs-secondary-color);
    font-size: 0.78rem;
    line-height: 1.4;
}

/* ── Prompt textarea ─────────────────────────────────── */
.prompt-textarea {
    font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    resize: vertical;
}

/* ── Placeholder / coming soon ───────────────────────── */
.placeholder-panel {
    background: var(--port-surface);
    border: 2px dashed var(--port-border);
    border-radius: 0.5rem;
    padding: 3rem 2rem;
    text-align: center;
    color: var(--bs-secondary-color);
}
