/* ============================================================
   MT5 Mobile Manager — Mobile-first Dark Theme CSS
   Matches the MAUI app's visual design exactly
   ============================================================ */

:root {
    --bg: #1f1f1f;
    --card: #181818;
    --surface: #252526;
    --input: #313131;
    --border: #3c3c3c;
    --divider: #3c3c3c;
    --primary: #0078d4;
    --primary-rgb: 0, 120, 212;
    --primary-dark: #005fb8;
    --on-primary: #ffffff;
    --brand: #0078d4;
    --on-brand: #ffffff;
    --action-primary: #0078d4;
    --action-primary-hover: #106ebe;
    --on-action-primary: #ffffff;
    --action-danger: #c50f1f;
    --action-danger-hover: #a80000;
    --on-action-danger: #ffffff;
    --success: #4caf50;
    --danger: #f44336;
    --warning: #ffc107;
    --text-primary: #cccccc;
    --text-secondary: #a7a7a7;
    --text-muted: #6f6f6f;
    --hover: #2a2d2e;
    --soft: rgba(0, 120, 212, 0.13);
    --row-border: rgba(204, 204, 204, 0.12);
    --overlay: rgba(0, 0, 0, 0.65);
    --shadow: rgba(0, 0, 0, 0.45);
    --radius: 14px;
    --radius-sm: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --tab-height: 56px;
}

:root[data-theme="normal"] {
    --bg: #ffffff;
    --card: #ffffff;
    --surface: #f8f8f8;
    --input: #ffffff;
    --border: #d0d0d0;
    --divider: #d0d0d0;
    --primary: #005fb8;
    --primary-rgb: 0, 95, 184;
    --primary-dark: #004c93;
    --on-primary: #ffffff;
    --brand: #005fb8;
    --on-brand: #ffffff;
    --action-primary: #005fb8;
    --action-primary-hover: #0258a8;
    --on-action-primary: #ffffff;
    --action-danger: #c42b1c;
    --action-danger-hover: #a4262c;
    --on-action-danger: #ffffff;
    --success: #16803a;
    --danger: #d32f2f;
    --warning: #b7791f;
    --text-primary: #3b3b3b;
    --text-secondary: #555555;
    --text-muted: #7a7a7a;
    --hover: #f2f2f2;
    --soft: rgba(0, 95, 184, 0.09);
    --row-border: #e6e6e6;
    --overlay: rgba(15, 23, 42, 0.28);
    --shadow: rgba(15, 23, 42, 0.14);
}

:root[data-theme="monokai"] {
    --bg: #272822;
    --card: #201f1b;
    --surface: #3e3d32;
    --input: #414339;
    --border: #75715e;
    --divider: #4a493d;
    --primary: #fd971f;
    --primary-rgb: 253, 151, 31;
    --primary-dark: #d97800;
    --on-primary: #1e1f1c;
    --brand: #fd971f;
    --on-brand: #1e1f1c;
    --action-primary: #fd971f;
    --action-primary-hover: #f57c00;
    --on-action-primary: #1e1f1c;
    --action-danger: #f92672;
    --action-danger-hover: #d4145f;
    --on-action-danger: #ffffff;
    --success: #a6e22e;
    --danger: #f92672;
    --warning: #e6db74;
    --text-primary: #f8f8f2;
    --text-secondary: #ccccc7;
    --text-muted: #90908a;
    --hover: #3e3d32;
    --soft: rgba(166, 226, 46, 0.12);
    --row-border: rgba(117, 113, 94, 0.45);
    --overlay: rgba(30, 31, 28, 0.78);
    --shadow: rgba(0, 0, 0, 0.58);
}

:root[data-theme="contrast"] {
    --bg: #000000;
    --card: #050505;
    --surface: #101010;
    --input: #000000;
    --border: #ffffff;
    --divider: #ffffff;
    --primary: #569cd6;
    --primary-rgb: 86, 156, 214;
    --primary-dark: #3794ff;
    --on-primary: #000000;
    --brand: #ffff00;
    --on-brand: #000000;
    --action-primary: #ffff00;
    --action-primary-hover: #dcdc00;
    --on-action-primary: #000000;
    --action-danger: #f44747;
    --action-danger-hover: #ff6b6b;
    --on-action-danger: #000000;
    --success: #b5cea8;
    --danger: #f44747;
    --warning: #dcdcaa;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --text-muted: #c8c8c8;
    --hover: #1a1a1a;
    --soft: rgba(255, 255, 255, 0.18);
    --row-border: rgba(255, 255, 255, 0.5);
    --overlay: rgba(0, 0, 0, 0.82);
    --shadow: rgba(0, 0, 0, 0.7);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    color-scheme: dark;
}

html[data-theme="normal"] {
    color-scheme: light;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    padding-top: var(--safe-top);
    padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 8px);
}

/* Standalone PWA: extra top padding for status bar */
@media (display-mode: standalone) {
    body { padding-top: calc(var(--safe-top) + 12px); }
}

a { color: var(--primary); text-decoration: none; }

/* ============ Page Header / Toolbar ============ */
.page-header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.page-header h1 {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}
.page-header .back-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.theme-icon-toggle {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, color .15s, border-color .15s, transform .1s;
}
.theme-icon-toggle:active {
    transform: scale(0.94);
}
.theme-icon-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}
.theme-icon {
    display: block;
}
.appearance-overlay {
    position: fixed;
    inset: 0;
    z-index: 700;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: calc(var(--safe-top) + 56px) 12px calc(var(--safe-bottom) + 84px);
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity .16s ease;
}
.appearance-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.appearance-overlay[hidden] {
    display: none;
}
.appearance-sheet {
    width: min(310px, calc(100vw - 24px));
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 18px 48px var(--shadow);
    overflow: hidden;
}
.appearance-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.appearance-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}
.appearance-close {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card);
    color: var(--text-secondary);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.appearance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
}
.appearance-option {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    min-height: 78px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}
.appearance-option.active {
    border-color: var(--primary);
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px var(--primary);
}
.theme-swatch {
    display: block;
    width: 100%;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.16);
}
.swatch-dark { background: linear-gradient(135deg, #1f1f1f 0 45%, #181818 45% 70%, #0078d4 70%); }
.swatch-light { background: linear-gradient(135deg, #ffffff 0 45%, #f8f8f8 45% 70%, #005fb8 70%); border-color: #d0d0d0; }
.swatch-monokai { background: linear-gradient(135deg, #272822 0 30%, #201f1b 30% 52%, #f92672 52% 68%, #fd971f 68% 84%, #a6e22e 84%); }
.swatch-contrast { background: linear-gradient(135deg, #000000 0 38%, #101010 38% 62%, #ffffff 62% 76%, #ffff00 76%); border-color: #ffffff; }

/* ============ Bottom Tab Bar ============ */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tab-height) + var(--safe-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 6px;
    padding-bottom: var(--safe-bottom);
    z-index: 200;
}
.tab-bar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--text-muted);
    font-size: 10px;
    text-decoration: none;
    padding: 4px 8px;
    min-width: 56px;
    transition: color .15s;
}
.tab-bar a .tab-icon { font-size: 22px; line-height: 1; }
.tab-bar a .tab-icon-img { width: 22px; height: 22px; border-radius: 4px; object-fit: cover; }
.tab-bar a.active, .tab-bar a:hover { color: var(--primary); }

/* ============ Cards ============ */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin: 4px 12px;
}

/* ============ Summary Header (sticky sub-header) ============ */
.summary-bar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    gap: 8px;
}
.summary-bar .stat { flex: 1; }
.summary-bar .stat-label { font-size: 11px; color: var(--text-muted); }
.summary-bar .stat-value { font-size: 18px; font-weight: 700; }
.summary-bar .stat-value.primary { color: var(--primary); }

/* ============ Badge ============ */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
}
.badge-buy { background: var(--success); color: #fff; }
.badge-sell { background: var(--danger); color: #fff; }
.badge-muted { background: var(--surface); color: var(--text-secondary); }

/* ============ Form Elements ============ */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}
.form-control {
    width: 100%;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color .2s;
    -webkit-appearance: none;
    appearance: none;
}
.form-control:focus { border-color: var(--primary); }
.form-control::placeholder { color: var(--text-muted); }
.form-control:-webkit-autofill,
.form-control:-webkit-autofill:hover,
.form-control:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0px 1000px var(--input) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    transition: background-color 5000s ease-in-out 0s;
}

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238892b0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn-primary { background: var(--action-primary); color: var(--on-action-primary); }
.btn-primary:hover { background: var(--action-primary-hover); }
.btn-danger { background: var(--action-danger); color: var(--on-action-danger); }
.btn-danger:hover { background: var(--action-danger-hover); }
.btn-sm { padding: 8px 16px; font-size: 13px; width: auto; border-radius: 8px; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ============ Error / Alert ============ */
.alert {
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-danger { background: rgba(244,67,54,0.2); border: 1px solid rgba(244,67,54,0.33); color: var(--danger); }
.alert-success { background: rgba(76,175,80,0.2); border: 1px solid rgba(76,175,80,0.33); color: var(--success); }

/* ============ Login Page ============ */
.login-wrapper {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    /* Ambient brand glow + faint blueprint grid — pure CSS, follows the theme */
    background:
        radial-gradient(ellipse 90% 55% at 15% -5%, rgba(var(--primary-rgb), 0.14), transparent 60%),
        radial-gradient(ellipse 80% 50% at 110% 105%, rgba(var(--primary-rgb), 0.10), transparent 60%),
        repeating-linear-gradient(0deg, transparent 0 39px, rgba(var(--primary-rgb), 0.035) 39px 40px),
        repeating-linear-gradient(90deg, transparent 0 39px, rgba(var(--primary-rgb), 0.035) 39px 40px),
        var(--bg);
}
.login-box { max-width: 400px; width: 100%; }
.login-wrapper-split {
    justify-content: center;
    align-items: center;
    gap: 0;
    padding: clamp(48px, 8vh, 78px) clamp(36px, 5vw, 72px);
    background: var(--bg);
}
.login-wrapper-split .login-box {
    max-width: none;
    flex: 0 0 min(34vw, 520px);
    width: min(34vw, 520px);
    min-width: 440px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 36px 44px;
    margin-left: 0;
}
.login-wrapper-split .login-visual {
    flex: 1 1 min(58vw, 920px);
    height: clamp(560px, calc(100dvh - 150px), 720px);
    max-width: 960px;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 50% 34%, rgba(var(--primary-rgb), 0.14), transparent 34%),
        linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
    border-right: 1px solid rgba(17, 24, 39, 0.08);
}
.login-wrapper-split .login-visual-stage {
    width: min(100%, 720px);
    height: 100%;
    padding: 48px 56px 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
}
.login-visual-mark {
    position: relative;
    width: clamp(220px, 22vw, 260px);
    aspect-ratio: 1.62 / 1;
    display: grid;
    place-items: center;
}
.login-visual-mark::before,
.login-logo-mark::before,
.login-mini-mark::before {
    content: "";
    position: absolute;
    inset: 2px;
    z-index: 2;
    pointer-events: none;
    border-radius: inherit;
    background:
        linear-gradient(90deg, var(--primary), var(--primary-dark)) left top / 44px 2px no-repeat,
        linear-gradient(180deg, var(--primary), var(--primary-dark)) left top / 2px 44px no-repeat,
        linear-gradient(270deg, var(--primary-dark), var(--primary)) right top / 44px 2px no-repeat,
        linear-gradient(180deg, var(--primary-dark), var(--primary)) right top / 2px 44px no-repeat,
        linear-gradient(90deg, var(--primary-dark), var(--primary)) left bottom / 44px 2px no-repeat,
        linear-gradient(0deg, var(--primary-dark), var(--primary)) left bottom / 2px 44px no-repeat,
        linear-gradient(270deg, var(--primary), var(--primary-dark)) right bottom / 44px 2px no-repeat,
        linear-gradient(0deg, var(--primary), var(--primary-dark)) right bottom / 2px 44px no-repeat;
    filter: drop-shadow(0 0 6px rgba(var(--primary-rgb), 0.8));
    opacity: 0.92;
}
.login-visual-mark::before {
    inset: -12px;
    border-radius: 18px;
    background-size: 68px 3px, 3px 68px, 68px 3px, 3px 68px,
                     68px 3px, 3px 68px, 68px 3px, 3px 68px;
}
/* Uploaded desktop artwork replaces the default M5 mark: the corner brackets
   are suppressed and the image sits alone in a rounded glow frame. */
.login-visual-stage.login-artwork-image .login-visual-mark::before {
    content: none;
}
.login-visual-stage.login-artwork-image .login-visual-mark {
    width: min(100%, clamp(280px, 30vw, 420px));
    aspect-ratio: auto;
    padding: 20px;
    border-radius: 18px;
    background: linear-gradient(180deg, #101828 0%, #0b1220 100%);
    box-shadow:
        0 0 24px rgba(var(--primary-rgb), 0.55),
        0 0 64px rgba(var(--primary-rgb), 0.22);
}
.login-visual-stage.login-artwork-image .login-visual-mark img {
    width: 100%;
    height: auto;
    max-height: min(52vh, 420px);
    object-fit: contain;
}
.login-logo-mark,
.login-mini-mark {
    position: relative;
}
.login-visual-mark img,
.login-visual-mark svg {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}
.login-visual-mark span {
    font-size: clamp(44px, 4.5vw, 64px);
    font-weight: 800;
    letter-spacing: 6px;
    color: var(--primary);
}
.login-visual-title {
    font-size: clamp(24px, 2.45vw, 38px);
    font-weight: 800;
    letter-spacing: 1.2px;
    color: #344150;
    text-transform: uppercase;
    text-align: center;
}
.login-visual-subtitle {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2.6px;
    text-transform: uppercase;
    color: var(--primary);
    text-align: center;
}
.login-mini-brand {
    display: none !important;
}
.login-logo {
    text-align: center;
    margin-bottom: 36px;
}
.login-logo .logo-icon,
.login-logo .login-logo-mark {
    width: 72px; height: 72px;
    background: var(--brand);
    border-radius: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    color: var(--on-brand);
    margin-bottom: 14px;
    box-shadow:
        0 0 0 1px rgba(var(--primary-rgb), 0.35),
        0 0 34px rgba(var(--primary-rgb), 0.28),
        0 14px 30px var(--shadow);
}
.login-logo h2 {
    font-size: 28px;
    color: var(--brand);
    font-weight: 800;
    letter-spacing: 1.2px;
}
.login-logo p {
    font-size: 11.5px;
    color: var(--text-secondary);
    margin-top: 5px;
    text-transform: uppercase;
    letter-spacing: 2.4px;
}
/* Broker-theme SVG logo: transparent plate, mark carries its own colors */
.login-logo .logo-icon-svg {
    background: var(--soft);
    padding: 10px;
}
.login-logo .logo-icon-svg svg,
.login-logo .login-logo-mark svg,
.login-logo .login-logo-mark img { width: 100%; height: 100%; display: block; object-fit: contain; }

.login-card {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px 24px 24px;
    box-shadow:
        0 0 0 1px rgba(var(--primary-rgb), 0.08),
        0 0 28px rgba(var(--primary-rgb), 0.12),
        0 22px 50px var(--shadow);
    overflow: hidden;
}
/* Brand accent bar across the top edge of the card */
.login-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--primary) 22%, var(--primary-dark) 78%, transparent);
    box-shadow: 0 0 12px rgba(var(--primary-rgb), 0.9);
}
.login-card .form-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--text-muted);
    font-weight: 700;
}
.login-card .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
}
.login-wrapper .btn-primary {
    background: linear-gradient(135deg, var(--action-primary), var(--primary-dark));
    letter-spacing: .6px;
    font-weight: 700;
    box-shadow:
        0 0 18px rgba(var(--primary-rgb), 0.22),
        0 8px 22px rgba(var(--primary-rgb), 0.34);
    transition: filter .15s, transform .1s;
}
.login-wrapper .btn-primary:hover { filter: brightness(1.08); }
.login-wrapper .btn-primary:active { transform: translateY(1px); }
.login-wrapper .footer-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 18px;
}
.login-wrapper .footer-text::before {
    content: "";
    width: 11px; height: 11px;
    flex-shrink: 0;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4'%3E%3Crect x='4' y='11' width='16' height='9' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E") center/contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4'%3E%3Crect x='4' y='11' width='16' height='9' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E") center/contain no-repeat;
}
.login-wrapper-split .login-card {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}
.login-wrapper-split .login-footer-split {
    margin-top: 14px;
    color: rgba(255,255,255,0.66);
}
.login-wrapper-split .disclaimer-box {
    width: 100%;
    max-width: 420px;
    margin: 14px auto 0;
    background: rgba(255, 255, 255, 0.035);
    border-color: rgba(255, 255, 255, 0.10);
}

/* Broker dropdown */
.broker-list {
    max-height: 200px;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 4px;
}
.broker-item {
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background .15s;
}
.broker-item:hover { background: var(--surface); }
.broker-item .name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.broker-item .server { font-size: 11px; color: var(--text-secondary); }
.broker-item .sdk { font-size: 10px; color: var(--warning); font-weight: 600; }

/* ============ List Items ============ */
.list-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin: 4px 12px;
    cursor: pointer;
    transition: background .1s;
}
.list-item:active { background: var(--surface); }

.item-row { display: flex; justify-content: space-between; align-items: center; }
.item-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.item-subtitle { font-size: 12px; color: var(--text-secondary); }
.item-value { font-size: 15px; font-weight: 600; }
.item-muted { font-size: 11px; color: var(--text-muted); }

.detail-row { display: flex; gap: 16px; margin-top: 8px; flex-wrap: wrap; }
.detail-col { display: flex; flex-direction: column; gap: 1px; }
.detail-label { font-size: 10px; color: var(--text-muted); }
.detail-value { font-size: 12px; color: var(--text-secondary); }

/* ============ Menu Items (Settings page) ============ */
.menu-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: background .1s;
}
.menu-item:active { background: var(--surface); }
.menu-item .menu-icon { font-size: 22px; flex-shrink: 0; }
.menu-item .menu-text { flex: 1; }
.menu-item .menu-text .title { font-size: 15px; color: var(--text-primary); }
.menu-item .menu-text .subtitle { font-size: 10px; color: var(--text-muted); }
.menu-item .menu-arrow { font-size: 16px; color: var(--text-muted); }
.menu-item.primary .menu-text .title { color: var(--primary); }
.menu-item.warning .menu-text .title { color: var(--warning); }

/* ============ Search Bar ============ */
.search-bar {
    padding: 8px 12px;
}
.search-bar input {
    width: 100%;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar input::placeholder { color: var(--text-muted); }

/* ============ Date Range ============ */
.date-range {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.date-range input[type="date"] {
    flex: 1;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    color-scheme: inherit;
}
.date-range .arrow { color: var(--text-muted); font-size: 16px; }

/* ============ Profit Colors ============ */
.profit-positive { color: var(--success) !important; }
.profit-negative { color: var(--danger) !important; }

/* ============ Footer Text ============ */
.footer-text {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 16px;
}

/* ============ Spinner ============ */
.spinner {
    display: flex;
    justify-content: center;
    padding: 40px;
}
.spinner::after {
    content: '';
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Scrollable page body ============ */
.page-body {
    padding-bottom: 16px;
}

/* ============ Pull-to-refresh hint ============ */
.empty-state {
    text-align: center;
    padding: 60px 32px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ============ Broker brand on authenticated Accounts page ============ */
.account-page-brand { display:flex; align-items:center; gap:10px; min-width:0; }
.account-page-logo { width:38px; height:38px; border-radius:50%; display:grid; place-items:center; flex-shrink:0; background:var(--brand); color:var(--on-brand); font-size:13px; font-weight:800; overflow:hidden; }
.account-page-logo.logo-rich { background:var(--soft); }
.account-page-logo img, .account-page-logo svg { width:34px; height:34px; display:block; object-fit:contain; }
.account-page-app-name { color:var(--brand); font-size:10px; line-height:1.1; font-weight:800; letter-spacing:.03em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:220px; }
.account-page-brand h1 { margin-top:2px; }

/* ============ Connection status card ============ */
.connection-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 0 16px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.connection-card .logo-sm {
    width: 40px; height: 40px;
    background: var(--brand);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--on-brand);
    flex-shrink: 0;
}
.connection-card .logo-sm.logo-rich { background: var(--soft); overflow: hidden; }
.connection-card .logo-sm img,
.connection-card .logo-sm svg { width: 34px; height: 34px; object-fit: contain; display: block; }

/* ============ Account Detail ============ */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 12px;
}
.detail-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}
.detail-card .label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.detail-card .value { font-size: 16px; font-weight: 600; }

/* ============ Symbol list ============ */
.symbol-card .price-row {
    display: flex;
    gap: 16px;
    margin-top: 8px;
}
.symbol-card .price-col { display: flex; flex-direction: column; gap: 1px; }

/* ============ Responsive tweaks ============ */
/* Mobile: keep compact layout */
@media (min-width: 768px) and (max-width: 1023px) {
    body { max-width: 720px; margin: 0 auto; }
    .tab-bar { max-width: 720px; left: 50%; transform: translateX(-50%); }
}
/* Desktop: use 80% viewport width, let tables breathe */
@media (min-width: 1024px) {
    body { max-width: 80vw; margin: 0 auto; }
    .tab-bar { max-width: 80vw; left: 50%; transform: translateX(-50%); }
}

/* Sticky table headers: the wrapper scrolls vertically within the viewport,
   the thead sticks at the wrapper top; .page-header (z-index:100) stays above. */
.rpt-scroll, .bill-scroll, .sum-scroll-wrap, .sharing-table-wrap,
.cs-scroll, .opr-scroll, .tic-scroll, .tl-scroll {
    overflow: auto;
    max-height: calc(100dvh - var(--tab-height) - var(--safe-bottom) - 120px);
}
.rpt-tbl thead th, .bill-table thead th, .sum-tbl thead th,
.sharing-table thead th, .cs-tbl thead th, .opr-tbl thead th,
.tic-table thead th, .tl-tbl thead th {
    position: sticky;
    top: 0;
    z-index: 50;
}
/* These headers use a translucent tint by default; make them opaque so
   scrolled rows do not show through. */
.bill-table thead th, .sharing-table thead th, .opr-tbl thead th {
    background: var(--surface);
}

/* iOS overscroll color */
html { background: var(--bg); }

/* Remove default blue highlight on links */
* { -webkit-tap-highlight-color: transparent; }

/* Smooth scrolling */
html { scroll-behavior: smooth; }

/* Hide scrollbar on mobile but keep scrollable */
@media (max-width: 767px) {
    ::-webkit-scrollbar { width: 0; height: 0; }
}
/* Desktop: show horizontal scrollbar on table containers */
@media (min-width: 768px) {
    ::-webkit-scrollbar { width: 6px; height: 6px; }
    ::-webkit-scrollbar-track { background: var(--surface); border-radius: 3px; }
    ::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
    ::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
}

/* ============ App-wide theme enforcement ============ */
html[data-theme],
html[data-theme] body,
body[data-theme] {
    background: var(--bg) !important;
    color: var(--text-primary);
}

html[data-theme] .page-body,
body[data-theme] .page-body {
    background: var(--bg) !important;
}

html[data-theme] .page-header,
html[data-theme] .tab-bar,
html[data-theme] .card,
html[data-theme] .login-card,
html[data-theme] .list-item,
html[data-theme] .menu-item,
html[data-theme] .connection-card,
html[data-theme] .summary-bar,
html[data-theme] .date-range,
html[data-theme] .detail-card,
html[data-theme] .broker-list,
html[data-theme] .broker-dropdown,
html[data-theme] .rpt-toolbar,
html[data-theme] .ccd-toolbar,
html[data-theme] .cs-toolbar,
html[data-theme] .cs-card,
html[data-theme] .tl-card,
html[data-theme] .tl-status-bar,
html[data-theme] .cs-section-head,
html[data-theme] .tl-section-head,
html[data-theme] .ccd-client,
html[data-theme] .client-setting-card,
html[data-theme] .sp-comm-card,
html[data-theme] .summary-grid div,
html[data-theme] .mode-option,
html[data-theme] .modal-box,
html[data-theme] .disc-modal-box,
html[data-theme] .cs-drop,
html[data-theme] #pwa-banner {
    background: var(--card) !important;
    border-color: var(--border) !important;
    color: var(--text-primary);
    box-shadow: 0 10px 30px var(--shadow);
}

html[data-theme] .rpt-section-head,
html[data-theme] .rpt-foot td,
html[data-theme] .sum-total-row td,
html[data-theme] .sum-th,
html[data-theme] .rpt-th,
html[data-theme] .ccd-tabs,
html[data-theme] .ccd-client-header,
html[data-theme] .ccd-pth,
html[data-theme] .ccd-pth-sticky,
html[data-theme] .client-setting-head,
html[data-theme] .sp-comm-head,
html[data-theme] .sp-comm-table th,
html[data-theme] .cs-th,
html[data-theme] .cs-foot td,
html[data-theme] .tl-th,
html[data-theme] .result-table th,
html[data-theme] .disc-modal-header {
    background: var(--surface) !important;
    border-color: var(--border) !important;
    color: var(--text-primary);
}

html[data-theme] .login-card {
    box-shadow:
        0 0 0 1px rgba(var(--primary-rgb), 0.10),
        0 0 30px rgba(var(--primary-rgb), 0.18),
        0 22px 50px var(--shadow) !important;
}

html[data-theme] .rpt-tbl,
html[data-theme] .sum-tbl,
html[data-theme] .ccd-pivot,
html[data-theme] .ccd-detail-tbl,
html[data-theme] .sp-comm-table,
html[data-theme] .ca-sub-tbl,
html[data-theme] .ph-sub-tbl,
html[data-theme] .jt-tbl,
html[data-theme] .cg-sym-tbl,
html[data-theme] .cs-tbl,
html[data-theme] .tl-tbl,
html[data-theme] .cli-table,
html[data-theme] .result-table {
    background: var(--card) !important;
    color: var(--text-secondary) !important;
}

html[data-theme] .rpt-td,
html[data-theme] .sum-td,
html[data-theme] .ccd-dtd,
html[data-theme] .ccd-ptd,
html[data-theme] .sp-comm-table td,
html[data-theme] .ca-sub-tbl tbody td,
html[data-theme] .ph-sub-tbl tbody td,
html[data-theme] .opr-td,
html[data-theme] .jt-tbl tbody td,
html[data-theme] .cg-sym-tbl td,
html[data-theme] .cli-table-row td,
html[data-theme] .cs-td,
html[data-theme] .tl-td,
html[data-theme] .result-table th,
html[data-theme] .result-table td {
    border-bottom-color: var(--row-border) !important;
}

html[data-theme] .rpt-row:hover td,
html[data-theme] .sum-row:hover td,
html[data-theme] .ccd-drow:hover td,
html[data-theme] .ccd-prow:hover td,
html[data-theme] .ccd-prow:hover .ccd-ptd-sticky,
html[data-theme] .broker-item:hover,
html[data-theme] .broker-item.highlighted,
html[data-theme] .cs-row:hover td,
html[data-theme] .tl-row:hover td,
html[data-theme] .cli-table-row:hover,
html[data-theme] .list-item:active,
html[data-theme] .menu-item:active {
    background: var(--hover) !important;
}

html[data-theme] .broker-item,
html[data-theme] .disc-modal-text,
html[data-theme] .disclaimer-line,
html[data-theme] .item-subtitle,
html[data-theme] .detail-value,
html[data-theme] .rpt-mode,
html[data-theme] .cs-subtitle,
html[data-theme] .cs-lbl,
html[data-theme] .cs-time,
html[data-theme] .cs-card-label,
html[data-theme] .tl-subtitle,
html[data-theme] .tl-lbl,
html[data-theme] .tl-hint,
html[data-theme] .export-btn {
    color: var(--text-secondary) !important;
}

html[data-theme] .item-title,
html[data-theme] .menu-item .menu-text .title,
html[data-theme] .broker-item .name,
html[data-theme] .disc-modal-header,
html[data-theme] .sp-comm-table th,
html[data-theme] .sp-comm-table,
html[data-theme] .ccd-has-value,
html[data-theme] .ccd-ptd-sticky,
html[data-theme] .cs-card-value,
html[data-theme] .tl-status-bar {
    color: var(--text-primary) !important;
}

html[data-theme] .client-group,
html[data-theme] .sp-comm-head,
html[data-theme] .cs-section-head,
html[data-theme] .tl-card-head,
html[data-theme] .tl-section-head,
html[data-theme] .cs-link,
html[data-theme] .tl-link-input {
    color: var(--primary) !important;
}

html[data-theme] input,
html[data-theme] select,
html[data-theme] textarea,
html[data-theme] .form-control,
html[data-theme] .search-bar input,
html[data-theme] .rpt-date,
html[data-theme] .rpt-select,
html[data-theme] .ccd-search,
html[data-theme] .ccd-date,
html[data-theme] .ccd-select,
html[data-theme] .cs-input,
html[data-theme] .grp-search-input,
html[data-theme] .grp-select,
html[data-theme] .sp-comm-table input,
html[data-theme] .cs-input,
html[data-theme] .tl-input,
html[data-theme] .tl-link-input {
    background: var(--input) !important;
    border-color: var(--border) !important;
    color: var(--text-primary) !important;
    color-scheme: inherit !important;
}

html[data-theme="normal"] input,
html[data-theme="normal"] select,
html[data-theme="normal"] textarea,
html[data-theme="normal"] .form-control,
html[data-theme="normal"] .search-bar input,
html[data-theme="normal"] .rpt-date,
html[data-theme="normal"] .rpt-select,
html[data-theme="normal"] .ccd-search,
html[data-theme="normal"] .ccd-date,
html[data-theme="normal"] .ccd-select,
html[data-theme="normal"] .cs-input,
html[data-theme="normal"] .grp-search-input,
html[data-theme="normal"] .grp-select,
html[data-theme="normal"] .sp-comm-table input,
html[data-theme="normal"] .cs-input,
html[data-theme="normal"] .tl-input,
html[data-theme="normal"] .tl-link-input {
    color-scheme: light !important;
}

html[data-theme] input::placeholder,
html[data-theme] textarea::placeholder {
    color: var(--text-muted) !important;
}

html[data-theme] .rpt-mode.active {
    background: var(--action-primary) !important;
    border-color: var(--action-primary) !important;
    color: var(--on-action-primary, #fff) !important;
}

html[data-theme] .cs-btn-filter,
html[data-theme] .tl-btn-gen,
html[data-theme] .tl-btn-copy,
html[data-theme] .btn-primary,
html[data-theme] .search-btn {
    background: var(--action-primary) !important;
    border-color: var(--action-primary) !important;
    color: var(--on-action-primary, #fff) !important;
    box-shadow: none !important;
}

html[data-theme] .btn-danger {
    background: var(--action-danger) !important;
    border-color: var(--action-danger) !important;
    color: var(--on-action-danger, #fff) !important;
    box-shadow: none !important;
}

html[data-theme] .login-logo .logo-icon,
html[data-theme] .connection-card .logo-sm {
    background: var(--brand) !important;
    color: var(--on-brand) !important;
}

html[data-theme] .login-logo h2 {
    color: var(--brand) !important;
}

/* Broker-theme SVG logos keep their soft plate (the mark has its own colors) */
html[data-theme] .login-logo .logo-icon-svg {
    background: var(--soft) !important;
}

/* Keep the premium gradient CTA on the login screen in every user theme */
html[data-theme] .login-wrapper .btn-primary {
    background: linear-gradient(135deg, var(--action-primary), var(--primary-dark)) !important;
    box-shadow:
        0 0 18px rgba(var(--primary-rgb), 0.22),
        0 8px 22px rgba(var(--primary-rgb), 0.34) !important;
}

html[data-theme] .rpt-mode-group {
    background: var(--surface) !important;
    border-color: var(--border) !important;
}

html[data-theme] .modal-overlay,
html[data-theme] .disc-modal-overlay,
html[data-theme] #confirmOverlay,
html[data-theme] #posModal,
html[data-theme] #posConfirmOverlay {
    background: var(--overlay) !important;
}

html[data-theme] .form-control:-webkit-autofill,
html[data-theme] .form-control:-webkit-autofill:hover,
html[data-theme] .form-control:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0px 1000px var(--input) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
}

html[data-theme] .profit-positive,
html[data-theme] .badge-buy {
    color: var(--success) !important;
}

html[data-theme] .profit-negative,
html[data-theme] .badge-sell {
    color: var(--danger) !important;
}

html[data-theme] .badge-buy,
html[data-theme] .badge-sell {
    color: #fff !important;
}


/* ============ Desktop table enhancements ============ */
/* On desktop, tables use full container width; columns auto-size.
   !important overrides page-level <style> min-width values that load after app.css */
/* Only narrow touch-first devices use the vertical login. A wide touch-screen
   laptop keeps the established split layout; the mobile UA fallback is applied
   by Index.cshtml for WebViews that report unreliable pointer capabilities. */
@media (hover: none) and (pointer: coarse) and (max-width: 860px) {
    .login-wrapper-split {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
        width: 100% !important;
        min-height: 100dvh !important;
        background: var(--bg) !important;
        padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom)) !important;
        overflow-x: hidden !important;
    }
    .login-wrapper-split .login-visual {
        display: none !important;
    }
    .login-wrapper-split .login-mini-brand {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        width: 100%;
        max-width: 330px;
        margin: 0 auto 18px !important;
        text-align: center;
    }
    .login-wrapper-split .login-mini-title {
        color: var(--text-primary);
        width: 100%;
        max-width: 100%;
        font-size: clamp(20px, 5.2vw, 24px);
        font-weight: 800;
        line-height: 1.16;
        letter-spacing: 0.2px;
        overflow-wrap: anywhere;
        white-space: normal;
    }
    .login-wrapper-split .login-mini-subtitle {
        margin-top: 7px;
        color: var(--text-secondary);
        font-size: clamp(12px, 3.5vw, 14px);
        font-weight: 600;
        line-height: 1.35;
    }
    .login-wrapper-split .login-box {
        flex: none !important;
        width: min(100%, calc(100vw - 48px)) !important;
        max-width: 430px !important;
        min-width: 0 !important;
        margin: 0 auto !important;
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
    }
    .login-wrapper-split .login-card {
        max-width: 430px;
        width: min(430px, calc(100vw - 48px));
        min-width: 0;
        box-sizing: border-box;
        margin: 0 auto;
        padding: 22px 20px 20px;
        border-radius: 20px;
    }
    .login-wrapper-split .login-card .form-group {
        margin-bottom: 15px;
    }
    .login-wrapper-split .login-card .form-control {
        min-height: 48px;
        padding: 12px 14px;
        border-radius: 13px;
        font-size: 16px;
    }
    .login-wrapper-split .login-card .btn {
        min-height: 52px;
        border-radius: 14px;
        font-size: 16px;
    }
    .login-wrapper-split .broker-dropdown {
        max-height: min(34vh, 220px);
    }
    .login-wrapper-split .login-footer-split {
        margin: 14px 0 0;
        padding: 0 8px;
        line-height: 1.45;
    }
    .login-wrapper-split .disclaimer-box {
        max-width: none;
        width: 100%;
        margin: 18px 0 0;
        padding: 15px 16px 14px;
    }
    .login-wrapper-split .disclaimer-line {
        font-size: 12px;
        line-height: 1.52;
    }
}

@media (max-width: 420px) {
    .login-wrapper-split.login-compact {
        padding-left: 12px;
        padding-right: 12px;
    }
    .login-wrapper-split.login-compact .login-box {
        max-width: 100%;
    }
    .login-wrapper-split.login-compact .login-card {
        padding: 20px 16px 18px;
    }
    .login-wrapper-split.login-compact .disclaimer-box {
        padding: 14px;
    }
}

@media (max-width: 600px) {
    .appearance-overlay {
        align-items: flex-start;
        justify-content: center;
        padding: calc(var(--safe-top) + 64px) 16px calc(var(--safe-bottom) + 84px);
    }
    .appearance-sheet {
        width: min(450px, 100%);
    }
    .appearance-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .rpt-scroll, .sum-tbl-wrap {
        overflow-x: auto;
    }
    .rpt-tbl, .sum-tbl {
        min-width: 100% !important;
        width: 100%;
        table-layout: auto;
    }
    /* Slightly larger font for readability on desktop */
    .rpt-td, .sum-td { font-size: 13px; }
    .rpt-th, .sum-th { font-size: 11px; }
    /* List items can be wider */
    .list-item { margin: 4px 16px; }
    /* Cards get a bit more breathing room */
    .card { margin: 4px 16px; }
    .detail-grid { margin: 12px 16px; }
    /* Summary bar stats larger on desktop */
    .summary-bar .stat-value { font-size: 20px; }
}

/* Foreground, same-app manager notifications */
#app-notification-host{position:fixed;z-index:12000;top:max(12px,env(safe-area-inset-top));left:12px;right:12px;display:grid;justify-items:center;gap:9px;pointer-events:none}
.app-notification-toast{pointer-events:auto;width:min(100%,430px);margin-left:auto;margin-right:auto;border:1px solid rgba(255,255,255,.13);border-left:4px solid #6c63ff;border-radius:13px;background:rgba(19,23,39,.96);color:#fff;box-shadow:0 10px 32px rgba(0,0,0,.38);padding:12px;display:flex;align-items:center;gap:11px;text-align:left;opacity:0;transform:translateY(-12px);transition:opacity .2s,transform .2s;cursor:pointer;backdrop-filter:blur(16px)}
.app-notification-toast.show{opacity:1;transform:translateY(0)}
.app-notification-toast.type-trade{border-left-color:#2196f3}.app-notification-toast.type-account-create{border-left-color:#8b7cff}.app-notification-toast.type-deposit-withdrawal{border-left-color:#4caf50}
.app-notification-icon{width:34px;height:34px;flex:0 0 34px;border-radius:10px;background:rgba(255,255,255,.09);display:grid;place-items:center;font-size:17px}.app-notification-copy{display:block;flex:1;min-width:0}.app-notification-copy strong{display:block;font-size:13px;line-height:1.25}.app-notification-copy small{display:block;color:rgba(255,255,255,.72);font-size:11px;line-height:1.4;margin-top:3px}.app-notification-close{font-size:19px;color:rgba(255,255,255,.55);align-self:flex-start;line-height:1}
html[data-theme="normal"] .app-notification-toast{background:rgba(255,255,255,.97);color:#20243a;border-color:rgba(30,35,60,.13);box-shadow:0 10px 30px rgba(30,35,60,.2)}html[data-theme="normal"] .app-notification-copy small{color:#60677c}html[data-theme="normal"] .app-notification-close{color:#73798b}
