/* ══════════════════════════════════════════════
   Aphias Capital — Productivity Dashboard
   ══════════════════════════════════════════════ */

:root {
    --bg: #F0F2F5;
    --bg-card: #FFFFFF;
    --bg-hover: #E8EBF0;
    --bg-input: #FFFFFF;
    --border: #D0D4DC;
    --text: #1A1A1A;
    --text2: #444444;
    --muted: #6B7280;
    --blue: #0066CC;
    --blue-light: #DBEAFE;
    --green: #16A34A;
    --green-light: #D1FAE5;
    --red: #DC2626;
    --red-light: #FEE2E2;
    --orange: #D97706;
    --orange-light: #FEF3C7;
    --purple: #7C3AED;
    --purple-light: #EDE9FE;
    --topbar-bg: #1A1A2E;
    --sidebar-bg: #1A1A2E;
    --sidebar-hover: #2A2A40;
    --sidebar-active: #3B82F6;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Topbar ── */
.topbar {
    height: 48px;
    background: var(--topbar-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: fixed; top: 0; left: 0; right: 0;
    z-index: 200;
}
.topbar-left { display: flex; align-items: center; gap: 8px; overflow: hidden; min-width: 0; flex: 1; }
.topbar-logo-img { height: 28px; width: auto; max-width: 120px; margin-right: 8px; object-fit: contain; flex-shrink: 0; }
.topbar-sub { color: #A0A8B8; font-size: 11px; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-status { color: var(--green); font-size: 8px; }
.topbar-user { color: #A0A8B8; font-size: 12px; }
.topbar-role { opacity: 0.6; }
.topbar-logout {
    color: #A0A8B8; text-decoration: none; font-size: 16px;
    margin-left: 12px; opacity: 0.6; transition: opacity 0.2s;
}
.topbar-logout:hover { opacity: 1; }

/* ── Hamburger ── */
.hamburger {
    display: none; background: none; border: none; cursor: pointer;
    padding: 4px; flex-direction: column; gap: 4px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: #A0A8B8; border-radius: 2px; }

/* ── Layout ── */
.app-body {
    display: flex;
    margin-top: 48px;
    min-height: calc(100vh - 48px);
}

/* ── Sidebar ── */
.sidebar {
    width: 200px;
    min-width: 200px;
    background: var(--sidebar-bg);
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 48px;
    bottom: 0;
    overflow-y: auto;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #CCCCDD;
    text-decoration: none;
    font-size: 13px;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #FFF; }
.nav-item.active { background: var(--sidebar-active); color: #FFF; }
.nav-icon { font-size: 14px; width: 20px; text-align: center; }

.sidebar-divider {
    border: none; border-top: 1px solid #333;
    margin: 8px 16px;
}

/* ── Content ── */
.content {
    flex: 1;
    margin-left: 200px;
    padding: 24px;
    max-width: 1600px;
    overflow-x: auto;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}
.page-subtitle {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

/* ── Period Selector ── */
.period-selector {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
}
.period-btn {
    padding: 6px 14px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
    text-decoration: none;
}
.period-btn:hover { background: var(--bg-hover); color: var(--text); }
.period-btn.active { background: var(--blue); color: #FFF; }

.period-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}
.period-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}
.period-nav-btn:hover { background: var(--bg-hover); }
.period-nav-btn.disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}
.period-nav-btn.today-btn {
    width: auto;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--blue);
    border-color: var(--blue);
}
.period-nav-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    padding: 0 6px;
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.card-icon { font-size: 15px; }

/* ── KPI Cards ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    text-align: center;
}
.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}
.kpi-label {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.kpi-sub {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}
.kpi-card.blue { border-top: 3px solid var(--blue); }
.kpi-card.green { border-top: 3px solid var(--green); }
.kpi-card.orange { border-top: 3px solid var(--orange); }
.kpi-card.purple { border-top: 3px solid var(--purple); }
.kpi-card.red { border-top: 3px solid var(--red); }

/* ── Department Section ── */
.dept-section {
    margin-bottom: 24px;
}
.dept-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: var(--radius) var(--radius) 0 0;
    font-weight: 600;
    font-size: 14px;
}
.dept-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}
.dept-bar {
    width: 4px;
    height: 20px;
    border-radius: 2px;
}

/* ── Tables ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table thead th {
    background: #F8F9FB;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text2);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table thead th.num { text-align: right; }
.data-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #EBEDF0;
    vertical-align: middle;
}
.data-table tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: #F8F9FB; }
.data-table tbody tr:last-child td { border-bottom: none; }

.emp-name-link {
    color: var(--blue);
    text-decoration: none;
    font-weight: 500;
}
.emp-name-link:hover { text-decoration: underline; }
.emp-title { font-size: 11px; color: var(--muted); display: block; }

.dept-totals td {
    font-weight: 600;
    background: #F8F9FB;
    border-top: 2px solid var(--border);
}

/* ── Metric Cells ── */
.metric-bar {
    display: flex;
    align-items: center;
    gap: 6px;
}
.metric-bar-fill {
    height: 6px;
    border-radius: 3px;
    min-width: 2px;
    transition: width 0.3s;
}

/* ── Employee Detail ── */
.emp-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}
.emp-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: #FFF;
    flex-shrink: 0;
}
.emp-info h1 { font-size: 22px; font-weight: 700; }
.emp-info .emp-meta { font-size: 13px; color: var(--muted); }

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #F0F0F0;
    font-size: 13px;
}
.metric-row:last-child { border-bottom: none; }
.metric-label { color: var(--muted); }
.metric-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Charts ── */
.chart-container {
    position: relative;
    height: 200px;
    margin: 12px 0 4px;
}

/* Simple CSS bar chart */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 150px;
    padding: 0;
}
.bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
}
.bar-stack {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 1px;
    height: 130px;
}
.bar {
    width: 100%;
    border-radius: 2px 2px 0 0;
    min-height: 0;
    transition: height 0.3s;
}
.bar.sent { background: var(--blue); }
.bar.received { background: #93C5FD; }
.bar.meetings { background: var(--purple); }
.bar-label {
    font-size: 9px;
    color: var(--muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.chart-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--muted);
}
.legend-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

/* ── Meeting List ── */
.meeting-list { list-style: none; }
.meeting-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #F0F0F0;
    align-items: flex-start;
}
.meeting-item:last-child { border-bottom: none; }
.meeting-date {
    min-width: 52px;
    text-align: center;
    flex-shrink: 0;
}
.meeting-date .day { font-size: 18px; font-weight: 700; line-height: 1; }
.meeting-date .month { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.meeting-date .time { font-size: 10px; color: var(--muted); }
.meeting-body { flex: 1; min-width: 0; }
.meeting-subject { font-weight: 500; font-size: 13px; }
.meeting-counterparty { font-size: 12px; color: var(--muted); margin-top: 2px; }
.meeting-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Recipients Table ── */
.recip-rank {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
}
.recip-rank.top3 { background: var(--blue-light); color: var(--blue); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    font-family: var(--font);
    text-decoration: none;
}
.btn-primary { background: var(--blue); color: #FFF; }
.btn-primary:hover { background: #0052A3; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text2);
}
.btn-outline:hover { background: var(--bg-hover); }

/* ── Sync Status ── */
.sync-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 12px;
    color: var(--muted);
}
.sync-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.sync-dot.ok { background: var(--green); }
.sync-dot.pending { background: var(--orange); }
.sync-dot.error { background: var(--red); }
.sync-dot.never { background: var(--border); }

/* ── Flash Messages ── */
.flash-container { margin-bottom: 16px; }
.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 8px;
}
.flash-success { background: var(--green-light); color: #065F46; border: 1px solid #A7F3D0; }
.flash-error { background: var(--red-light); color: #991B1B; border: 1px solid #FCA5A5; }

/* ── Productivity Score ── */
.prod-score {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 20px;
}
.score-ring {
    position: relative;
    width: 100px;
    height: 100px;
}
.score-ring svg { transform: rotate(-90deg); }
.score-ring circle {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
}
.score-ring .bg { stroke: #E5E7EB; }
.score-ring .fill { stroke: var(--blue); transition: stroke-dashoffset 0.6s; }
.score-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.score-text .value { font-size: 22px; font-weight: 700; }
.score-text .label { font-size: 10px; color: var(--muted); }

/* ── Two-col layout ── */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
    .two-col { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

@media (max-width: 768px) {
    .hamburger { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s;
        z-index: 150;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-overlay {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 140;
    }
    body.sidebar-open .sidebar-overlay { display: block; }
    .content { margin-left: 0; padding: 16px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .data-table { font-size: 12px; }
    .data-table thead th, .data-table tbody td { padding: 8px 6px; }
    .kpi-value { font-size: 22px; }
}

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

/* ── Loading spinner ── */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Back link ── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    margin-bottom: 12px;
}
.back-link:hover { color: var(--text); }
