/* GC Monitor PWA — Mobile-first responsive design */

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface-2: #22223a;
    --border: #2a2a44;
    --text: #e0e0e0;
    --text-dim: #8888aa;
    --accent: #667eea;
    --accent-2: #764ba2;
    --green: #28a745;
    --red: #dc3545;
    --yellow: #ffc107;
    --orange: #fd7e14;
    --radius: 10px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Navigation */
/* Cycle progress chevrons */
.chevron-bar {
    display: flex;
    gap: 2px;
    margin: 12px 0 4px;
    overflow: hidden;
}
.chevron {
    position: relative;
    flex: 1;
    padding: 6px 8px 6px 18px;
    background: var(--surface-2);
    color: var(--text-dim);
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%, 10px 50%);
    transition: background 0.3s, color 0.3s;
}
.chevron:first-child {
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%);
    padding-left: 10px;
}
.chevron:last-child {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 10px 50%);
}
.chevron.active {
    background: var(--accent);
    color: #fff;
    animation: pulse-chevron 1.2s ease-in-out infinite;
}
.chevron.complete {
    background: var(--green);
    color: #fff;
    animation: none;
}
.chevron.error {
    background: var(--red);
    color: #fff;
    animation: none;
}
@keyframes pulse-chevron {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
.step-detail {
    font-size: 0.75rem;
    color: var(--text-dim);
    min-height: 1.1em;
    margin-bottom: 4px;
}

/* Warning banner */
.warning-banner {
    background: var(--orange);
    color: #000;
    padding: 8px 16px;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    position: relative;
}
.warning-dismiss {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #000;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
}

.nav-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    backdrop-filter: blur(10px);
}

.nav-brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--accent);
    white-space: nowrap;
}

.nav-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.nav-tab {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.nav-tab.active {
    background: var(--accent);
    color: #fff;
}

.nav-tab:hover:not(.active) {
    background: var(--surface-2);
    color: var(--text);
}

.nav-status {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }
.status-dot.warning { background: var(--yellow); }

.status-label {
    font-size: 11px;
    color: var(--text-dim);
}

/* Page container */
.page-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 12px;
}

.page { display: none; }
.page.active { display: block; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.card h2 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text);
}

.card h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text-dim);
}

.subtitle {
    color: var(--text-dim);
    font-size: 12px;
    margin-bottom: 12px;
}

/* Gauge */
.gauge-card {
    text-align: center;
}

.gauge-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 16px;
}

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    text-transform: uppercase;
}

.badge.bullish { background: rgba(40, 167, 69, 0.2); color: var(--green); }
.badge.bearish { background: rgba(220, 53, 69, 0.2); color: var(--red); }
.badge.neutral { background: rgba(136, 136, 170, 0.2); color: var(--text-dim); }

.gauge-container {
    margin: 0 auto;
    max-width: 400px;
}

.gauge-bar-track {
    position: relative;
    height: 24px;
    background: var(--surface-2);
    border-radius: 12px;
    overflow: visible;
    display: flex;
}

.gauge-zone {
    height: 100%;
    transition: width 0.5s ease;
}

.gauge-zone.lower { background: rgba(220, 53, 69, 0.3); border-radius: 12px 0 0 12px; }
.gauge-zone.target { background: rgba(40, 167, 69, 0.3); }
.gauge-zone.upper { background: rgba(253, 126, 20, 0.3); border-radius: 0 12px 12px 0; }

.gauge-needle {
    position: absolute;
    top: -4px;
    width: 4px;
    height: 32px;
    background: var(--accent);
    border-radius: 2px;
    transition: left 0.5s ease;
    left: 50%;
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.6);
}

.gauge-labels {
    position: relative;
    height: 18px;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-dim);
}

.gauge-value {
    font-size: 36px;
    font-weight: 700;
    margin: 12px 0 4px;
    color: var(--accent);
}

.gauge-status {
    font-size: 13px;
    color: var(--text-dim);
}

.gauge-status.alert { color: var(--orange); font-weight: 600; }
.gauge-status.ok { color: var(--green); }

/* Metrics grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

@media (min-width: 600px) {
    .metrics-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.metric-card {
    text-align: center;
    padding: 12px;
}

.metric-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 20px;
    font-weight: 600;
    margin-top: 4px;
}

/* Control buttons */
.control-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 8px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--green); color: #fff; }
.btn-warning { background: var(--orange); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }

.btn:active { transform: scale(0.97); }

/* Feedback */
.feedback {
    font-size: 12px;
    padding: 6px 0;
    min-height: 24px;
}

.feedback.success { color: var(--green); }
.feedback.error { color: var(--red); }

/* Tables */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 2px solid var(--border);
    color: var(--text-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

td {
    padding: 7px 6px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td.empty {
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
}

tr.short td { color: var(--red); }
tr.eligible td:first-child { border-left: 3px solid var(--accent); }

/* Status badges in tables */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.filled { background: rgba(40, 167, 69, 0.2); color: var(--green); }
.status-badge.submitted { background: rgba(102, 126, 234, 0.2); color: var(--accent); }
.status-badge.cancelled { background: rgba(220, 53, 69, 0.2); color: var(--red); }

/* Forms */
fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
}

legend {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    padding: 0 8px;
}

.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.form-group {
    flex: 1;
    min-width: 120px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.form-group input {
    width: 100%;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* Summary grid */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    font-size: 13px;
}

.summary-grid .label { color: var(--text-dim); }
.summary-grid .value { font-weight: 600; text-align: right; }

/* Docs layout */
.docs-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 12px;
    align-items: start;
}

.docs-sidebar {
    position: sticky;
    top: 60px;
    max-height: calc(100vh - 72px);
    overflow-y: auto;
}

.docs-sidebar h3 {
    margin-bottom: 12px;
}

.docs-nav-category {
    margin-bottom: 10px;
}

.docs-nav-category-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    margin-bottom: 4px;
    padding: 0 4px;
}

.docs-nav-link {
    display: block;
    padding: 5px 8px;
    font-size: 13px;
    color: var(--text-dim);
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.docs-nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
}

.docs-nav-link.active {
    background: rgba(102, 126, 234, 0.15);
    color: var(--accent);
}

/* Docs article rendered markdown */
.docs-article {
    min-height: 300px;
    line-height: 1.65;
}

.docs-article h1 {
    font-size: 22px;
    margin-bottom: 8px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.docs-article h2 {
    font-size: 17px;
    margin: 20px 0 8px;
    color: var(--text);
}

.docs-article h3 {
    font-size: 15px;
    margin: 16px 0 6px;
    color: var(--text);
}

.docs-article p {
    margin: 8px 0;
}

.docs-article blockquote {
    border-left: 3px solid var(--accent);
    padding: 4px 12px;
    margin: 8px 0;
    color: var(--text-dim);
    font-size: 13px;
}

.docs-article pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    font-size: 13px;
    margin: 10px 0;
}

.docs-article code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}

.docs-article :not(pre) > code {
    background: var(--surface-2);
    padding: 2px 5px;
    border-radius: 3px;
}

.docs-article table {
    margin: 10px 0;
}

.docs-article ul, .docs-article ol {
    padding-left: 20px;
    margin: 8px 0;
}

.docs-article li {
    margin: 3px 0;
}

.docs-article a {
    color: var(--accent);
    text-decoration: none;
}

.docs-article a:hover {
    text-decoration: underline;
}

.docs-article hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.docs-back-btn {
    display: none;
    margin-bottom: 12px;
}

/* Activity Feed */
.activity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-icon:hover {
    background: var(--surface-2);
    color: var(--text);
}

.activity-feed {
    max-height: 280px;
    overflow-y: auto;
    font-size: 13px;
}

.activity-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
    font-size: 12px;
}

.activity-entry {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.activity-icon {
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1.4;
}

.activity-msg {
    flex: 1;
    line-height: 1.4;
    word-break: break-word;
}

.activity-time {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.4;
}

.activity-error .activity-msg { color: var(--red); }
.activity-order .activity-msg { color: var(--accent); }
.activity-status .activity-msg { color: var(--yellow); }
.activity-reprice .activity-msg { color: var(--orange); }

/* Responsive */
@media (max-width: 768px) {
    .docs-layout {
        grid-template-columns: 1fr;
    }
    .docs-sidebar {
        position: static;
        max-height: none;
    }
    .docs-sidebar.hidden-mobile {
        display: none;
    }
    .docs-back-btn {
        display: inline-block;
    }
}

@media (max-width: 480px) {
    .nav-brand { font-size: 14px; }
    .nav-tab { font-size: 12px; padding: 5px 8px; }
    .gauge-value { font-size: 28px; }
    .metric-value { font-size: 16px; }
    .form-row { flex-direction: column; }
    .form-group { min-width: 100%; }
}

/* --- Log Viewer --- */

.log-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.log-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.log-viewer {
    background: #0a0a14;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.5;
    max-height: 70vh;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.log-line {
    padding: 1px 0;
}

.log-line.log-warning {
    color: var(--orange);
}

.log-line.log-error {
    color: var(--red);
    font-weight: 600;
}

.log-line.log-debug {
    color: var(--text-dim);
}

/* --- User Menu --- */
.user-menu {
    position: relative;
    margin-right: 0.75rem;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    transition: background 0.15s;
}

.user-menu-trigger:hover {
    background: var(--surface-2);
}

.user-name {
    font-size: 0.85rem;
    color: var(--text);
}

.user-role {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 700;
}

.user-role.admin { background: var(--accent); color: #fff; }
.user-role.viewer { background: var(--surface-2); color: var(--text-dim); }

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 1000;
    overflow: hidden;
}

.user-dropdown button {
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}

.user-dropdown button:hover {
    background: var(--surface-2);
}

/* --- Modal Dialogs --- */
.modal-overlay {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-card.modal-wide {
    max-width: 700px;
}

.modal-card h3 {
    margin-bottom: 1rem;
}

.modal-card h4 {
    margin: 0.75rem 0 0.5rem;
}

.modal-card hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* --- User Admin Table --- */
.user-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.user-table th,
.user-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.user-table th {
    color: var(--text-dim);
    font-weight: 600;
}

.badge.ok { background: var(--green); color: #fff; }
.badge.danger { background: var(--red); color: #fff; }

.btn-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
}

.btn-danger {
    background: var(--red);
    color: #fff;
    border: none;
    cursor: pointer;
}

.btn-danger:hover { opacity: 0.85; }

/* --- Audit Log --- */
.audit-log-section {
    max-height: 300px;
    overflow-y: auto;
}

.audit-details {
    font-size: 0.75rem;
    color: var(--text-dim);
    max-width: 300px;
    word-break: break-word;
}
