/* PO Monitor Dashboard Styles */

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

:root {
    /* SMS Store Brand Colors */
    --brand-red: #e4222e;
    --brand-blue: #2e468a;
    --brand-yellow: #fcd702;
    --brand-gray: #a3a3a3;
    --brand-text: #1f2f5f;

    /* Dashboard Theme (dark, aligned with brand) */
    --bg: #0d1520;
    --bg-elevated: #111d2b;
    --surface: #142030;
    --surface-2: #182840;
    --surface-hover: #1e3350;
    --border: rgba(46, 70, 138, 0.25);
    --border-strong: rgba(46, 70, 138, 0.38);
    --text: #e8edf9;
    --text-muted: #94a0bc;
    --accent: #2e468a;
    --accent-hover: #3b5aaa;
    --accent-soft: rgba(46, 70, 138, 0.18);
    --green: #37d67a;
    --green-bg: rgba(55, 214, 122, 0.15);
    --yellow: #fcd702;
    --yellow-bg: rgba(252, 215, 2, 0.16);
    --red: #e4222e;
    --red-bg: rgba(228, 34, 46, 0.18);
    --gray: #a3a3a3;
    --gray-bg: rgba(163, 163, 163, 0.16);
    --radius: 10px;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

html {
    background: var(--bg);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(46, 70, 138, 0.12), transparent 28%),
        linear-gradient(180deg, #0d1520 0%, #0f1824 100%);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.app-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    padding: 24px 18px;
    background: rgba(10, 15, 29, 0.94);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(12px);
    transition: width 0.2s ease, padding 0.2s ease, transform 0.2s ease;
}

.body-sidebar-collapsed .app-shell {
    grid-template-columns: 84px minmax(0, 1fr);
}

.body-sidebar-collapsed .sidebar {
    padding: 24px 10px;
}

.body-sidebar-collapsed .brand-name,
.body-sidebar-collapsed .nav-meta {
    display: none;
}

.body-sidebar-collapsed .nav-collapse-btn .nav-label {
    display: inline;
    font-size: 0;
}

.body-sidebar-collapsed .nav-collapse-btn .nav-label::before {
    content: '»';
    font-size: 1rem;
}

.body-sidebar-collapsed .sidebar .nav-item:not(.nav-collapse-btn) .nav-label {
    display: none;
}

.body-sidebar-collapsed .sidebar-brand {
    justify-content: center;
}

.body-sidebar-collapsed .nav-item {
    justify-content: center;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 22px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.brand-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 14px;
    background: #ffffff;
    padding: 6px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
}

.brand-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.brand-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 12px;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid transparent;
    transition: all 0.18s ease;
}

.nav-item:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border);
}

.nav-item.active {
    color: var(--text);
    background: linear-gradient(180deg, rgba(111, 140, 255, 0.18), rgba(111, 140, 255, 0.08));
    border-color: rgba(111, 140, 255, 0.35);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.nav-label {
    font-size: 0.92rem;
    font-weight: 600;
}

.nav-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.nav-item.active .nav-meta {
    color: #c8d3ff;
}

.main-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    padding: 26px 28px 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin-bottom: 18px;
}

.eyebrow {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-collapse-btn {
    margin-top: 8px;
    width: 100%;
    background: rgba(255, 255, 255, 0.02);
}

.nav-collapse-btn:hover {
    border-color: var(--accent);
    color: var(--accent-hover);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.auto-refresh-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.lang-switcher-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.lang-switcher {
    min-width: 140px;
}

.auto-refresh-label input[type="checkbox"] {
    accent-color: var(--accent);
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s, transform 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.filters-card,
.panel {
    background: rgba(21, 29, 51, 0.88);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.filters-card {
    padding: 16px 18px;
}

.filters {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-input, .filter-select {
    padding: 9px 12px;
    background: rgba(9, 14, 27, 0.9);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-input:focus, .filter-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(111, 140, 255, 0.15);
}

.filter-input {
    width: 300px;
    max-width: 100%;
}

.po-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-left: auto;
}

.content-area {
    padding: 18px 28px 28px;
}

.widgets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.widget-card {
    background: rgba(21, 29, 51, 0.88);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 16px 18px;
}

.widget-filter {
    text-align: left;
    cursor: pointer;
}

.widget-filter:hover {
    border-color: rgba(111, 140, 255, 0.45);
    transform: translateY(-1px);
}

.widget-filter.active {
    border-color: rgba(111, 140, 255, 0.8);
    box-shadow: 0 0 0 2px rgba(111, 140, 255, 0.18), var(--shadow);
}

.widget-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
}

.widget-value {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--text);
}

.panel {
    padding: 8px 0;
    overflow: hidden;
}

.chart-panel {
    padding: 18px;
    margin-bottom: 18px;
}

.chart-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.chart-metric-selector,
.chart-period-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.metric-chip,
.period-chip {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.03);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.84rem;
}

.metric-chip.active,
.period-chip.active {
    color: var(--text);
    border-color: rgba(111, 140, 255, 0.8);
    background: rgba(111, 140, 255, 0.12);
}

.chart-wrap {
    width: 100%;
    min-height: 280px;
}

.chart-date-input {
    min-width: 150px;
}

.empty-state {
    text-align: center;
    padding: 72px 24px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state h2 {
    font-size: 1.2rem;
    color: var(--text);
    margin-bottom: 8px;
}

.empty-state code {
    background: var(--bg-elevated);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    table-layout: fixed;
}

thead th {
    position: relative;
    text-align: left;
    padding: 14px 16px;
    padding-right: 24px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.col-resizer {
    position: absolute;
    top: 8px;
    right: 2px;
    width: 12px;
    height: calc(100% - 16px);
    cursor: col-resize;
    user-select: none;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
    border-left: 1px solid rgba(140, 160, 210, 0.22);
}

.col-resizer::before {
    content: '⋮';
    color: rgba(148, 160, 188, 0.9);
    font-size: 12px;
    line-height: 1;
}

.col-resizer:hover,
.col-resizer.active {
    background: rgba(111, 140, 255, 0.22);
    border-left-color: rgba(111, 140, 255, 0.65);
}

.col-resizer:hover::before,
.col-resizer.active::before {
    color: #c8d3ff;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.025);
}

tbody td {
    padding: 12px 16px;
    vertical-align: middle;
    white-space: nowrap;
}

td.po-number {
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: #b5c4ff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-green {
    background: var(--green-bg);
    color: var(--green);
}

.status-yellow {
    background: var(--yellow-bg);
    color: var(--yellow);
}

.status-red {
    background: var(--red-bg);
    color: var(--red);
}

.status-gray {
    background: var(--gray-bg);
    color: var(--gray);
}

.action-yes {
    color: var(--red);
    font-weight: 700;
}

.action-no {
    color: var(--text-muted);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    width: min(95%, 1100px);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.detail-info {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.detail-value {
    font-size: 0.95rem;
    font-weight: 500;
}

.timeline-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* --- Two-column detail layout --- */
.detail-two-col {
    display: grid;
    grid-template-columns: 45% 1fr;
    gap: 20px;
    margin-top: 0;
}

.detail-two-col .timeline-section {
    min-width: 0;
    overflow-y: auto;
    max-height: 60vh;
    padding-right: 4px;
}

.detail-two-col .notes-section {
    min-width: 0;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    overflow-y: auto;
    max-height: 60vh;
}

.notes-section .notes-placeholder {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 40px 16px;
}

.notes-section .notes-header {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.notes-section .notes-body {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

.notes-section .notes-field {
    margin-bottom: 10px;
}

.notes-section .notes-field-label {
    font-size: 0.78rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 2px;
}

.notes-section .notes-field-value {
    font-size: 0.9rem;
    color: var(--text);
}

/* Clickable timeline events */
.timeline-event.clickable {
    cursor: pointer;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.timeline-event.clickable:hover {
    background: rgba(255,255,255,0.04);
    border-color: var(--border);
}

.timeline-event.clickable.active {
    background: rgba(111, 140, 255, 0.08);
    border-color: var(--accent);
}

.timeline-event.clickable.active::before {
    background: var(--green);
    box-shadow: 0 0 0 3px rgba(55, 214, 122, 0.25);
}

/* Responsive: stack on small screens */
@media (max-width: 640px) {
    .detail-two-col {
        grid-template-columns: 1fr;
    }
    .detail-two-col .timeline-section,
    .detail-two-col .notes-section {
        max-height: 40vh;
    }
}

.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border);
}

.timeline-event {
    position: relative;
    margin-bottom: 16px;
    padding-bottom: 8px;
}

.timeline-event::before {
    content: '';
    position: absolute;
    left: -22px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
}

.timeline-event:first-child::before {
    background: var(--green);
}

.timeline-event .event-status {
    font-weight: 600;
    margin-bottom: 2px;
}

.timeline-event .event-time {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.raw-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    margin-top: 4px;
    transition: all 0.2s;
}

.raw-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.raw-json {
    display: none;
    margin-top: 8px;
    background: rgba(9, 14, 27, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
    color: var(--text-muted);
}

.raw-json.visible {
    display: block;
}

.no-results {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

@media (max-width: 1080px) {
    .app-shell {
        grid-template-columns: 220px minmax(0, 1fr);
    }

    .topbar,
    .content-area {
        padding-left: 20px;
        padding-right: 20px;
    }
}

@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 16px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-brand {
        padding-bottom: 16px;
        margin-bottom: 14px;
    }

    .sidebar-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .nav-item {
        min-height: 52px;
    }

    .topbar {
        padding: 18px 16px 0;
    }

    .content-area {
        padding: 16px;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-input,
    .filter-select {
        width: 100%;
    }

    .po-count {
        margin-left: 0;
    }

    thead th,
    tbody td {
        padding: 10px 12px;
    }
}

@media (max-width: 560px) {
    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 1.45rem;
    }

    table {
        font-size: 0.82rem;
    }

    .col-hide-mobile {
        display: none;
    }
}
