/**
 * WeCanna App Shell - mobile-first PWA design with tablet override.
 *
 * Layout modes:
 *   - Phone (≤767px): always compact (bottom bar). No toggle.
 *   - Tablet (768-1199px): compact by default, can toggle to desktop.
 *   - Desktop (≥1200px): always desktop (sidebar). No toggle.
 *
 * The body class .force-desktop or .force-compact overrides default behavior.
 */

/* ========== RESET / BASE ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #0a0a0a;
    color: #e8f5e8;
    line-height: 1.5;
    overscroll-behavior-y: none;
    -webkit-font-smoothing: antialiased;
}
a { color: #4ade80; text-decoration: none; transition: 0.2s; }
a:hover { color: #86efac; }
img { max-width: 100%; height: auto; }

:root {
    --primary: #4ade80;
    --primary-dim: #22c55e;
    --accent: #facc15;
    --accent-dim: #f59e0b;
    --bg-dark: #0a0a0a;
    --panel-bg: #141414;
    --panel-bg-2: #1a1a1a;
    --border: #222;
    --border-active: rgba(74, 222, 128, 0.3);
    --text-main: #e8f5e8;
    --text-muted: #888;
    --text-dim: #555;
    --bottom-nav-height: 60px;
    --sidebar-width: 240px;
    --topbar-height: 60px;
}

/* ========== APP SHELL CONTAINER ========== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ========== SIDEBAR (DESKTOP) ========== */
.sidebar {
    width: var(--sidebar-width);
    background: #0d0d0d;
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    padding: 1.25rem 0.75rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
}
.sidebar .brand {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 1.5rem;
    padding: 0 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar .nav-links {
    list-style: none;
    flex: 1;
}
.sidebar .nav-links li { margin-bottom: 0.25rem; }
.sidebar .nav-links a {
    display: flex;
    align-items: center;
    padding: 0.85rem 0.9rem;
    color: var(--text-muted);
    border-radius: 8px;
    transition: 0.15s;
    font-size: 0.92rem;
    font-weight: 500;
}
.sidebar .nav-links a:hover {
    background: var(--panel-bg);
    color: var(--text-main);
}
.sidebar .nav-links a.active {
    background: rgba(74, 222, 128, 0.1);
    color: var(--primary);
    font-weight: 700;
}
.sidebar .nav-icon {
    width: 22px;
    text-align: center;
    margin-right: 0.75rem;
    font-size: 1rem;
}
.sidebar .sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
    margin-top: 0.75rem;
}

/* ========== TOPBAR ========== */
.topbar {
    height: var(--topbar-height);
    background: rgba(10, 10, 10, 0.85);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar .page-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}
.top-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Global miner status badge */
.miner-status-badge {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.85rem;
    background: rgba(74, 222, 128, 0.1);
    border: 1px solid rgba(74, 222, 128, 0.3);
    border-radius: 20px;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: 0.2s;
}
.miner-status-badge:hover {
    background: rgba(74, 222, 128, 0.2);
    color: var(--primary);
}
body.session-active .miner-status-badge { display: inline-flex; }
.miner-status-badge .dot {
    width: 8px; height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}
.miner-status-badge.ready {
    background: rgba(250, 204, 21, 0.1);
    border-color: rgba(250, 204, 21, 0.4);
    color: var(--accent);
    animation: glow 2s ease-in-out infinite;
}
.miner-status-badge.ready .dot { background: var(--accent); }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
@keyframes glow {
    0%, 100% { box-shadow: 0 0 8px rgba(250,204,21,0.3); }
    50% { box-shadow: 0 0 16px rgba(250,204,21,0.6); }
}

/* User dropdown */
.user-dropdown { position: relative; }
.user-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.15s;
}
.user-trigger:hover { background: var(--panel-bg); }
.user-name { font-size: 0.85rem; font-weight: 600; }
.user-avatar {
    width: 32px; height: 32px;
    background: var(--panel-bg);
    border: 1px solid var(--border-active);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 0.85rem;
}
.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.5rem;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 220px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 1000;
    overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.9rem;
    color: var(--text-main);
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    transition: 0.15s;
    cursor: pointer;
    background: none;
    border-left: none;
    border-right: none;
    border-top: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--panel-bg-2); color: var(--primary); }
.dropdown-item i { width: 18px; color: var(--primary); }

/* View toggle in dropdown - only shown on tablets */
#viewToggleItem { display: none; }
body.is-tablet #viewToggleItem,
body.is-tablet-device #viewToggleItem { display: flex; }


/* ========== MAIN CONTENT ========== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.page-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

/* ========== BOTTOM BAR (MOBILE/TABLET) ========== */
.bottom-bar {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0));
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: rgba(10, 10, 10, 0.95);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    z-index: 1000;
}
.bottom-bar-inner {
    display: flex;
    height: var(--bottom-nav-height);
    max-width: 600px;
    margin: 0 auto;
}
.bottom-bar .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.7rem;
    transition: 0.15s;
    text-decoration: none;
    gap: 0.2rem;
}
.bottom-bar .nav-item i { font-size: 1.15rem; }
.bottom-bar .nav-item.active { color: var(--primary); }
.bottom-bar .nav-item.active i {
    transform: translateY(-2px);
    filter: drop-shadow(0 0 4px rgba(74,222,128,0.5));
}

/* ========== LAYOUT BREAKPOINTS ========== */

/* PHONE (0-767px): always compact, no override allowed */
@media (max-width: 767px) {
    .sidebar { display: none !important; }
    .main-content {
        margin-left: 0;
        width: 100%;
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0));
    }
    .bottom-bar { display: block; }
    .page-content { padding: 1rem; }
    .topbar { padding: 0 1rem; }
    .user-name { display: none; }
    .topbar .page-title { font-size: 1rem; }
    body { } /* phone class added by JS */
}

/* TABLET (768-1199px): compact by default, override-able */
@media (min-width: 768px) and (max-width: 1199px) {
    /* Default: compact mode (bottom bar) */
    .sidebar { display: none; }
    .main-content {
        margin-left: 0;
        width: 100%;
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0));
    }
    .bottom-bar { display: block; }
    .page-content { padding: 1.25rem; }

    /* Override: force-desktop class flips to sidebar mode */
    body.force-desktop .sidebar { display: flex; }
    body.force-desktop .main-content {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
        padding-bottom: 0;
    }
    body.force-desktop .bottom-bar { display: none; }
}

/* DESKTOP (1200px+): always desktop, no override */
@media (min-width: 1200px) {
    .sidebar { display: flex; }
    .main-content {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
        padding-bottom: 0;
    }
    .bottom-bar { display: none; }
}

/* ========== SHARED COMPONENTS ========== */
.card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    overflow-x: auto; /* Add this line */
}
.card h1, .card h2 {
    color: var(--primary);
    margin-bottom: 1rem;
    font-size: 1.25rem;
}
.card.highlight {
    background: linear-gradient(135deg, rgba(74,222,128,0.06), rgba(168,85,247,0.04));
    border-color: var(--border-active);
}

form label {
    display: block;
    margin: 1rem 0 0.4rem;
    color: #86efac;
    font-size: 0.85rem;
    font-weight: 500;
}
form input[type=text], form input[type=email], form input[type=password],
form input[type=number], form input[type=url], form textarea, form select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-size: 1rem;
    font-family: inherit;
    transition: 0.15s;
}
form input:focus, form textarea:focus, form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.1);
}
form button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--primary);
    color: #000;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: 0.15s;
    margin-top: 1rem;
    text-decoration: none;
}
form button:hover, .btn:hover {
    background: var(--primary-dim);
    transform: translateY(-1px);
}
.btn.outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border-active);
}
.btn.outline:hover { background: rgba(74,222,128,0.1); }
.btn.danger { background: #ef4444; color: white; }
.btn.danger:hover { background: #dc2626; }
.btn.accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    color: #000;
}

.muted { color: var(--text-muted); font-size: 0.88rem; }
.address {
    font-family: ui-monospace, monospace;
    font-size: 0.8rem;
    word-break: break-all;
    color: var(--text-muted);
}

table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; }
th, td { padding: 0.7rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: #86efac; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 1px; }

.balance-big {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--primary);
    line-height: 1;
}
.balance-big span { font-size: 1.25rem; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}
.stat-grid .stat {
    background: var(--bg-dark);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.stat .label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.3rem;
}
.stat .value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
}

.warning {
    background: rgba(250, 204, 21, 0.08);
    border: 1px solid rgba(250, 204, 21, 0.3);
    color: #fef3c7;
    padding: 0.85rem 1rem;
    border-radius: 8px;
    margin: 1rem 0;
}
.success {
    background: rgba(74, 222, 128, 0.08);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: var(--primary);
    padding: 0.85rem 1rem;
    border-radius: 8px;
    margin: 1rem 0;
}

footer {
    text-align: center;
    padding: 1.5rem;
    color: rgba(74, 222, 128, 0.5);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* ========== UTILITY ========== */
.hidden { display: none !important; }
@media (max-width: 767px) {
    .hide-mobile { display: none !important; }
}
@media (min-width: 1200px) {
    .hide-desktop { display: none !important; }
}

/* =====================================================================
 * iOS / Android SAFE AREA HANDLING (added 2026-05)
 *
 * Problem: with apple-mobile-web-app-status-bar-style="black-translucent"
 * + viewport-fit=cover, the browser draws our page UNDER the iOS status
 * bar. Without explicit safe-area-inset-top padding, our topbar content
 * (page title, mining badge, user avatar) collides with the system
 * clock / wifi / battery icons.
 *
 * Fix: every "top-edge UI surface" (topbar, public nav, sidebar brand)
 * gets padding-top: env(safe-area-inset-top, 0) and an extended height
 * so its background fills the area UNDER the status bar - dark text on
 * dark background, no visual collision.
 * ===================================================================== */

/* The sticky topbar in the logged-in shell */
.topbar {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
}

/* The public (logged-out) nav bar */
.public-nav {
    padding-top: calc(1rem + env(safe-area-inset-top, 0px)) !important;
}

/* Desktop sidebar brand — make sure the logo doesn't tuck under the
   status bar in PWA standalone mode on iPad. */
.sidebar .brand {
    padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
}

/* iOS PWA standalone mode adjustments. The status bar isn't drawn over
   browser chrome but IS drawn over our page, so the inset matters most
   here. These rules nest inside a feature query so they only apply when
   the user has actually installed the PWA to their home screen. */
@media all and (display-mode: standalone) {
    body {
        /* Extend the body background up under the status bar to avoid
           a transparent strip. */
        background-color: #0a0a0a;
    }
    .topbar,
    .public-nav {
        /* In PWA mode iOS sometimes reports 0 for the inset on older
           devices. Provide a small fallback so the bar still drops
           below where the status bar would be. */
        padding-top: max(env(safe-area-inset-top, 0px), 12px);
    }
    .topbar {
        height: calc(var(--topbar-height) + max(env(safe-area-inset-top, 0px), 12px));
    }
}

/* Landscape on phones: status bar is to the LEFT or RIGHT, not the top,
   and iOS reports inset-top as 0 in landscape. We add lateral insets
   so the topbar content doesn't get eaten by the notch / dynamic island. */
@media (orientation: landscape) and (max-width: 1199px) {
    .topbar {
        padding-left: max(1.25rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.25rem, env(safe-area-inset-right, 0px));
    }
    .bottom-bar {
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }
}

