/* ─── UN_VIRAL Management — v1.9 ─── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #0a0a0a;
    --bg-card: #111111;
    --bg-input: #1a1a1a;
    --border: #222222;
    --text: #ffffff;
    --text-muted: #888888;
    --accent: #38d9a9;
    --accent-hover: #2bc49a;
    --danger: #ff4444;
    --warning: #ffaa00;
    --success: #38d9a9;
    --sidebar-width: 240px;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── LAYOUT ─── */

.app-layout { display: flex; min-height: 100vh; }

/* ─── SIDEBAR ─── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand h1 {
    font-family: var(--font);
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.sidebar-brand span {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent);
}

.sidebar-nav-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar-nav-wrap::-webkit-scrollbar { width: 3px; }
.sidebar-nav-wrap::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav-wrap::-webkit-scrollbar-thumb { background: #222; border-radius: 3px; }
.sidebar-nav-wrap::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.sidebar-nav { padding: 16px 0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.sidebar-nav a.active { color: var(--accent); border-left-color: var(--accent); background: rgba(56,217,169,0.05); }
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

.menu-toggle {
    display: none;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    width: 44px; height: 44px;
    cursor: pointer;
    font-size: 20px;
}

/* ─── MAIN CONTENT ─── */

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
    max-width: 100%;
}

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

.page-header h2 {
    font-family: var(--font);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ─── CARDS ─── */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.card-label {
    font-family: var(--font);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.card-value {
    font-family: var(--font);
    font-variant-numeric: tabular-nums;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.card-value.positive { color: var(--success); }
.card-value.negative { color: var(--danger); }
.card-value.neutral { color: var(--text); }

.card-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ─── TABLES ─── */

.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
}

.table-container > table { width: 100%; }

table { width: 100%; border-collapse: collapse; }

th {
    font-family: var(--font);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--font);
    border-radius: var(--radius-sm);
}

.status-badge.ativo, .status-badge.paga, .status-badge.entregue { color: var(--success); border: 1px solid var(--success); }
.status-badge.esgotado, .status-badge.reembolsada { color: var(--danger); border: 1px solid var(--danger); }
.status-badge.em-producao, .status-badge.enviada { color: var(--warning); border: 1px solid var(--warning); }
.status-badge.planeado { color: var(--text-muted); border: 1px solid var(--text-muted); }

/* ─── FORMS ─── */

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

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
    font-family: var(--font);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

input, select, textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 14px;
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
input[type="checkbox"] { width: 18px; height: 18px; border-radius: 4px; accent-color: var(--accent); cursor: pointer; }

/* ─── BUTTONS ─── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    border: none;
    border-radius: 50px;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #000; }
.btn-sm { padding: 6px 14px; font-size: 11px; border-radius: 50px; }

/* ─── MODAL ─── */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px;
}

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

.modal-header h3 { font-family: var(--font); font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 24px; cursor: pointer; border-radius: 50%; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
.modal-close:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ─── STOCK BAR ─── */

.stock-bar { width: 100%; height: 6px; background: var(--bg-input); border-radius: 3px; position: relative; overflow: hidden; }
.stock-bar-fill { height: 100%; background: var(--accent); transition: width 0.3s; border-radius: 3px; }
.stock-bar-fill.low { background: var(--warning); }
.stock-bar-fill.critical { background: var(--danger); }

.stock-sizes { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.stock-size { font-family: var(--font); font-variant-numeric: tabular-nums; font-size: 11px; font-weight: 500; color: var(--text-muted); padding: 2px 6px; border: 1px solid var(--border); border-radius: 4px; }
.stock-size.out { color: var(--danger); border-color: var(--danger); opacity: 0.5; }

/* ─── PERIOD FILTER ─── */

.period-filter { display: flex; gap: 4px; flex-wrap: wrap; }

.period-filter button {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50px;
    color: var(--text-muted);
    padding: 6px 14px;
    font-family: var(--font);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s;
}

.period-filter button:hover { color: var(--text); border-color: #444; }
.period-filter button.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ─── CHARTS ─── */

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    overflow: hidden;
}

.chart-card canvas { max-height: 280px; }
.chart-wrap { position: relative; width: 100%; height: 260px; }

.chart-card h4 {
    font-family: var(--font);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ─── EMPTY STATE ─── */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.empty-state h3 { font-family: var(--font); font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 8px; }

/* ─── ALERTS ─── */

.alert {
    padding: 14px 20px;
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid;
    border-radius: var(--radius-md);
}

.alert-success { color: var(--success); border-color: var(--success); background: rgba(56,217,169,0.05); }
.alert-error { color: var(--danger); border-color: var(--danger); background: rgba(255,68,68,0.05); }
.alert-warning { color: var(--warning); border-color: var(--warning); background: rgba(255,170,0,0.05); }

/* ─── RESPONSIVE ─── */

/* Tablets e telemóveis grandes */
@media (max-width: 768px) {
    /* SIDEBAR */
    .sidebar { transform: translateX(-100%); width: 85%; max-width: 320px; }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.5); }
    .menu-toggle { display: flex; align-items: center; justify-content: center; }

    /* LAYOUT */
    .main-content { margin-left: 0; padding: 14px; padding-top: 64px; }

    /* PAGE HEADER */
    .page-header { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 20px; }
    .page-header h2 { font-size: 20px; }
    .page-header > .btn,
    .page-header > button { width: 100%; }

    /* GRIDS */
    .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 20px; }
    .charts-grid { grid-template-columns: 1fr; gap: 10px; margin-bottom: 20px; }
    .form-grid { grid-template-columns: 1fr !important; gap: 12px; }
    .drop-grid { grid-template-columns: 1fr !important; }

    /* CARDS */
    .card { padding: 14px; border-radius: 14px; }
    .card-value { font-size: 18px; }

    /* TABLES — scroll horizontal em vez de cortar */
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-container::-webkit-scrollbar { height: 6px; }
    .table-container::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
    table { font-size: 12px; }
    td, th { padding: 9px 10px; }
    /* Scroll hint nas tabelas mais largas */
    .table-container::after {
        content: ''; position: sticky; right: 0; top: 0; bottom: 0;
        display: block; width: 0;
    }

    /* MODAL — quase fullscreen */
    .modal-overlay { padding: 8px; align-items: flex-start; padding-top: 16px; }
    .modal { padding: 18px; border-radius: 14px; margin: 0; max-height: calc(100vh - 32px); width: 100%; }
    .modal-header { margin-bottom: 16px; }
    .modal-header h3 { font-size: 16px; }
    .modal-footer { flex-direction: column-reverse; gap: 8px; padding-top: 14px; margin-top: 16px; }
    .modal-footer .btn { width: 100%; }

    /* FORM CONTROLS — touch-friendly (Apple guideline: 44px) */
    input, select, textarea { min-height: 44px; font-size: 16px; /* 16px evita auto-zoom em iOS */ }
    textarea { min-height: 80px; }
    input[type="checkbox"] { min-height: 0; width: 22px; height: 22px; }
    input[type="date"] { font-size: 14px; }

    /* BUTTONS */
    .btn { padding: 12px 18px; font-size: 12px; min-height: 44px; }
    .btn-sm { padding: 8px 14px; font-size: 11px; min-height: 36px; }

    /* PERIOD FILTER — quebra bem */
    .period-filter { flex-wrap: wrap; gap: 6px; }
    .period-filter button { flex: 1 1 auto; min-width: 0; min-height: 36px; padding: 8px 12px; }
    .period-custom { width: 100%; margin-left: 0; margin-top: 8px; flex-wrap: wrap; }
    .period-custom input[type="date"] { flex: 1 1 130px; width: auto; }

    /* SEARCH INPUTS (data-search-wrap) */
    [data-search-wrap] { flex-direction: column; align-items: stretch !important; gap: 8px; }
    [data-search-wrap] input[type="search"] { max-width: none !important; width: 100% !important; }

    /* UTILITIES */
    .flex.gap-8 { flex-wrap: wrap; }
    .text-right.mono { white-space: nowrap; }

    /* CHARTS — alturas mais pequenas */
    .chart-wrap { height: 220px; }
    .chart-card { padding: 14px; border-radius: 14px; }

    /* STATUS BADGES — mais pequenos */
    .status-badge { font-size: 10px; padding: 2px 8px; }
    .prod-status { font-size: 10px; padding: 3px 9px; }

    /* EMPTY STATE */
    .empty-state { padding: 40px 16px; }
    .empty-state h3 { font-size: 16px; }
}

/* Telemóveis pequenos */
@media (max-width: 480px) {
    .main-content { padding: 10px; padding-top: 60px; }
    .cards-grid { grid-template-columns: 1fr; gap: 8px; }
    .page-header h2 { font-size: 18px; }
    .card { padding: 12px; }
    .card-value { font-size: 17px; }
    .modal { padding: 14px; }
    .menu-toggle { top: 8px; left: 8px; width: 40px; height: 40px; }

    /* Tabelas — fonte ainda mais pequena para caber */
    table { font-size: 11px; }
    td, th { padding: 8px 8px; }

    /* Botões em ações de tabela — agrupados */
    td .btn-sm { padding: 6px 10px; min-height: 32px; min-width: 32px; }
}

/* Touch-specific (qualquer device touch, não só mobile) */
@media (hover: none) {
    .btn:active { transform: scale(0.97); }
    tr:hover td { background: transparent; } /* hover desnecessário em touch */
}

/* ─── UTILITIES ─── */

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mono { font-family: var(--font); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.flex-wrap { flex-wrap: wrap; }

/* ─── MARGIN BAR ─── */
.margin-bar { height: 6px; border-radius: 3px; background: #1a1a1a; overflow: hidden; }
.margin-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }

/* ─── iOS TOGGLE ─── */
.toggle { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #333; border-radius: 26px; transition: .3s; }
.toggle-slider::before { content: ''; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .3s; }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle[style*="width:36px"] .toggle-slider::before { height: 14px; width: 14px; }
.toggle[style*="width:36px"] input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle-label { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }

/* ─── PRODUCTION STATUS ─── */
.prod-status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 50px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.prod-status.pending { color: #888; border: 1px solid #444; }
.prod-status.producing { color: #4dabf7; border: 1px solid rgba(77,171,247,.3); }
.prod-status.done { color: #38d9a9; border: 1px solid rgba(56,217,169,.3); }
.prod-status.shipped { color: #b197fc; border: 1px solid rgba(177,151,252,.3); }
.prod-status.blocked { color: #ff4444; border: 1px solid rgba(255,68,68,.3); }

/* ─── CUSTOM DATE RANGE ─── */
.period-custom { display: inline-flex; align-items: center; gap: 6px; }
.period-custom input[type="date"] { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); padding: 6px 10px; font-family: var(--font); font-size: 11px; width: 136px; }
.period-custom input[type="date"]:focus { border-color: var(--accent); }
.period-custom span { color: var(--text-muted); font-size: 11px; }
