/* ============================================================
   BASE LAYOUT
   ============================================================ */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    display: flex;
    margin: 0;
    min-height: 100vh;
    background-color: #f0f2f5;
}

.main-content {
    display: flex;
    width: 100%;
    position: relative;
}

/* ============================================================
   SIDEBAR MENU
   ============================================================ */
.menu {
    width: 230px;
    min-width: 230px;
    background: #3e4e5c;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 16px rgba(0,0,0,0.22);
    transition: width 0.26s cubic-bezier(0.4,0,0.2,1),
                min-width 0.26s cubic-bezier(0.4,0,0.2,1);
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    z-index: 50;
}
.menu.collapsed {
    width: 0;
    min-width: 0;
}
.menu.hide-menu { display: none; }
.menu.hide-menu + .content { flex: 1; }

/* --- Header ------------------------------------------------ */
.menu-header {
    padding: 13px 12px 12px 58px; /* left gap for hamburger */
    display: flex;
    align-items: center;
    gap: 8px;
    background: #2e3c48;
    border-bottom: 1px solid #506070;
    flex-shrink: 0;
}
.menu-header svg { flex-shrink: 0; }
.menu-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #A30011;
    letter-spacing: 0.03em;
    white-space: nowrap;
    border: none;
    padding: 0;
}

/* --- Scrollable nav area ----------------------------------- */
.menu-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 0 12px;
    scrollbar-width: thin;
    scrollbar-color: #607080 transparent;
}
.menu-nav::-webkit-scrollbar { width: 3px; }
.menu-nav::-webkit-scrollbar-thumb { background: #607080; border-radius: 2px; }

/* Top-level links (Home, Blog, About) */
.nav-top {
    list-style: none;
    padding: 0;
    margin: 0;
}
.nav-top li a {
    display: block;
    padding: 8px 16px;
    color: #e4ecf4;
    text-decoration: none;
    font-size: 0.83rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.14s, color 0.14s;
}
.nav-top li a:hover { background: #4c5e6e; color: #fff; }
.nav-top li a.active { background: #1d4ed8; color: #fff; }

.nav-divider {
    margin: 6px 0;
    border: none;
    border-top: 1px solid #506070;
}

/* --- Collapsible sections ---------------------------------- */
.menu-section { margin-bottom: 0; }

.section-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #9dbdd4;
    font-size: 0.67rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
    transition: color 0.14s;
    margin-top: 10px;
}
.section-header:hover { color: #c8dcea; }
.section-header:first-child { margin-top: 4px; }

.section-header .chevron {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
    color: #9dbdd4;
    transition: transform 0.2s ease, color 0.14s;
}
.section-header:hover .chevron { color: #c8dcea; }
.menu-section.closed .section-header .chevron { transform: rotate(-90deg); }

.section-items {
    list-style: none;
    padding: 2px 0 0;
    margin: 0;
    max-height: 600px;
    overflow: hidden;
    transition: max-height 0.24s ease, opacity 0.18s ease;
    opacity: 1;
}
.menu-section.closed .section-items {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.section-items li a {
    display: block;
    padding: 7px 14px 7px 22px;
    color: #cfdde9;
    text-decoration: none;
    font-size: 0.815rem;
    white-space: nowrap;
    transition: background 0.14s, color 0.14s;
}
.section-items li a:hover { background: #4c5e6e; color: #fff; }
.section-items li a.active {
    color: #7dc4ff;
    background: rgba(59,130,246,0.18);
    font-weight: 500;
}

/* Broker items inside section-items */
.section-items .broker-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px 6px 22px;
}
.section-items .broker-menu-item img {
    height: 14px;
    max-width: 60px;
    object-fit: contain;
    filter: brightness(0) invert(1) opacity(0.7);
    flex-shrink: 0;
}
.section-items .broker-menu-item a {
    padding: 0;
    font-size: 0.78rem;
    color: #b8ccd9;
}
.section-items .broker-menu-item a:hover {
    background: transparent;
    color: #e4ecf4;
    text-decoration: underline;
}

/* Engine-control widget links */
#engine-control-widget-container .menu-link {
    display: block;
    padding: 7px 14px 7px 22px;
    text-decoration: none;
    font-size: 0.815rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.14s, color 0.14s;
}
#engine-control-widget-container .menu-link:hover { background: #4c5e6e; }
.menu-link.start-link { color: #7dc4ff; }
.menu-link.stop-link  { color: #Ac6515; }

/* Status widget inside menu */
.status-widget-menu {
    padding: 5px 14px 5px 22px;
    font-size: 0.76rem;
}
.status-widget-menu .status-item {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 2px;
    color: #b0c8d8;
}
.status-widget-menu .status-item span:first-child { color: #90adc0; }
.status-value { font-weight: 600; }
.status-running, .status-connected { color: #4ade80; }
.status-standby, .status-codegen   { color: #fbbf24; }
.status-stopped, .status-failed, .status-unknown { color: #f87171; }

/* --- Footer (auth button) ---------------------------------- */
.menu-footer {
    padding: 10px;
    border-top: 1px solid #506070;
    flex-shrink: 0;
}
.menu-auth-btn {
    display: block;
    text-align: center;
    padding: 8px 10px;
    border-radius: 5px;
    color: #fff;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: opacity 0.15s;
}
.menu-auth-btn:hover { opacity: 0.82; color: #fff; text-decoration: none; }
.menu-auth-logout { background: #b91c1c; }
.menu-auth-login  { background: #16a34a; }

/* ============================================================
   HAMBURGER TOGGLE
   ============================================================ */
.hamburger {
    position: fixed;
    top: 13px;
    left: 13px;
    z-index: 1100;
    cursor: pointer;
    background: #3e4e5c;
    border: 1px solid #607080;
    border-radius: 7px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    transition: background 0.18s;
}
.hamburger:hover { background: #4c5e6e; }
.hamburger svg path { stroke: #d0e0ec; }

/* ============================================================
   CONTENT AREA
   ============================================================ */
.content {
    flex: 1;
    min-width: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.content-body { flex-grow: 1; }

/* ============================================================
   BROKER LOGIN STATUS DOTS (top-right)
   ============================================================ */
.broker-status-indicator {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 1050;
    display: flex;
    gap: 8px;
    padding: 5px 8px;
    background: rgba(255,255,255,0.92);
    border-radius: 12px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.18);
}
.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    cursor: help;
}
.status-dot.upstox { background: #22c55e; }
.status-dot.kite   { background: #3b82f6; }

/* ============================================================
   MISC UTILITIES
   ============================================================ */
.error { color: #dc3545; font-weight: bold; }

.refresh-link {
    display: inline-flex;
    align-items: center;
    color: #555;
    text-decoration: none;
}
.refresh-link svg { width: 20px; height: 20px; transition: transform 0.5s ease; }
.refresh-link:hover svg { transform: rotate(180deg); }

.header-main {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 4px;
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
    text-align: center;
    padding: 20px;
    margin-top: auto;
    background-color: #f8f9fa;
    border-top: 1px solid #e7e7e7;
    font-size: 0.875em;
    color: #6c757d;
}
.footer a { color: #007bff; text-decoration: none; margin: 0 10px; }
.footer a:hover { text-decoration: underline; }
