/* ═══════════════════════════════════════════════════════════════
   LexFlow — Design System
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables (Dark) ── */
:root {
    --bg-main: #0b0b0b;
    --bg-panel: #111111;
    --bg-panel-hover: #1a1a1a;

    --text-main: #ffffff;
    --text-muted: #9ca3af;

    --primary-color: #dc2626;
    --primary-hover: #b91c1c;
    --primary-soft: rgba(220, 38, 38, 0.14);

    --accent-color: #6b7280;

    --border-color: #2b2b2b;

    /* Status */
    --status-pendente: #64748b;
    --status-andamento: #eab308;
    --status-validacao: #f97316;
    --status-concluido: #22c55e;
    --status-cancelado: #ef4444;

    --font-family: 'Inter', sans-serif;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);

    --topbar-height: 64px;
}

/* ── Light Theme ── */
:root[data-theme="light"] {
    --bg-main: #ffffff;
    --bg-panel: #f3f4f6;
    --bg-panel-hover: #e5e7eb;
    --text-main: #0b0b0b;
    --text-muted: #6b7280;
    --primary-color: #dc2626;
    --primary-hover: #b91c1c;
    --primary-soft: rgba(220, 38, 38, 0.10);
    --accent-color: #111827;
    --border-color: #d1d5db;
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.12), 0 4px 6px -4px rgb(0 0 0 / 0.12);
}

/* ── Reset & Base ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── App Layout ── */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    min-height: 0;
    overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════
   TOPBAR
   ══════════════════════════════════════════════════════════════ */
.topbar {
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    gap: 12px;
    flex-shrink: 0;
}

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: contain;
    display: block;
}

.logo-text h1 {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

.logo-text p {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ── Navigation ── */
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 1;
    justify-content: center;
    min-width: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.topbar-nav::-webkit-scrollbar { display: none; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 13px;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-item i { font-size: 17px; }

.nav-item:hover {
    background-color: var(--bg-panel-hover);
    color: var(--text-main);
}

.nav-item.active {
    background-color: var(--primary-soft);
    color: var(--primary-color);
}

/* ── Topbar Actions (user info, theme, logout) ── */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
    color: #fff;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
}

/* ══════════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════════ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.view-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.view-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px 32px 24px;
    position: relative;
}

/* ── Search Bar ── */
.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 7px 14px;
    width: 220px;
    max-width: 100%;
    transition: all 0.3s ease;
}

.search-bar:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.25);
}

.search-bar i {
    color: var(--text-muted);
    margin-right: 8px;
    flex-shrink: 0;
}

.search-bar input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    width: 100%;
    font-size: 13px;
    min-width: 0;
}

/* ══════════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════════ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.view-animate {
    animation: fadeIn 0.25s ease forwards;
}

/* ══════════════════════════════════════════════════════════════
   CARDS & FORMS
   ══════════════════════════════════════════════════════════════ */
.card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
}

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

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

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.form-control {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-family);
    transition: border-color 0.2s;
    width: 100%;
    min-width: 0;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

/* ── Buttons ── */
.btn {
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    font-family: var(--font-family);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-icon {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.btn-icon:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* ══════════════════════════════════════════════════════════════
   DATA TABLES
   ══════════════════════════════════════════════════════════════ */
.table-container {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: auto;
    box-shadow: var(--shadow-md);
    max-height: calc(100vh - 200px);
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th,
.data-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    text-align: left;
    white-space: normal;
    word-break: break-word;
    vertical-align: middle;
}

.data-table th {
    background-color: var(--bg-main);
    font-weight: 600;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    z-index: 3;
    font-size: 11px;
}

.data-table th:last-child,
.data-table td:last-child {
    border-right: none;
}

.table-filter-input {
    width: 100%;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-top: 4px;
    outline: none;
    font-family: var(--font-family);
}

.table-filter-input:focus {
    border-color: var(--primary-color);
}

.data-table tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.data-table tr.sla-warning {
    background-color: rgba(239, 68, 68, 0.08);
}

/* ── Inline Status Selects ── */
.status-select {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    color: inherit;
    padding: 5px 4px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    appearance: none;
    font-family: var(--font-family);
    transition: all 0.15s;
}

.status-select:hover {
    border-color: var(--border-color);
    background-color: var(--bg-main);
}

.status-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Status Colors */
.status-pendente  { color: var(--text-muted); background-color: rgba(148, 163, 184, 0.08); }
.status-andamento { color: var(--status-andamento); background-color: rgba(234, 179, 8, 0.08); }
.status-validacao { color: var(--status-validacao); background-color: rgba(249, 115, 22, 0.08); }
.status-concluido { color: var(--status-concluido); background-color: rgba(34, 197, 94, 0.08); }
.status-cancelado { color: var(--status-cancelado); background-color: rgba(239, 68, 68, 0.08); }

.badge {
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    display: inline-block;
    white-space: nowrap;
}

/* ══════════════════════════════════════════════════════════════
   DASHBOARD
   ══════════════════════════════════════════════════════════════ */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.dash-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.dash-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.dash-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
}

.dash-card.total::before    { background: linear-gradient(90deg, var(--primary-color), var(--primary-hover)); }
.dash-card.andamento::before { background: linear-gradient(90deg, var(--status-andamento), #ca8a04); }
.dash-card.atrasado::before  { background: linear-gradient(90deg, var(--status-cancelado), #b91c1c); }
.dash-card.concluido::before { background: linear-gradient(90deg, var(--status-concluido), #16a34a); }

.dash-card h3 {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

.dash-card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
}

/* ══════════════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    padding: 16px;
    animation: fadeIn 0.15s ease;
}

.modal-content {
    width: 100%;
    max-width: 900px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 20px;
    animation: slideUp 0.2s ease;
}

/* ══════════════════════════════════════════════════════════════
   AUTH OVERLAY
   ══════════════════════════════════════════════════════════════ */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    padding: 16px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px 24px;
    animation: slideUp 0.25s ease;
}

.auth-card h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-card p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.5;
}

.auth-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
    flex-wrap: wrap;
}

/* ══════════════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════════════ */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}

/* ══════════════════════════════════════════════════════════════
   UTILITIES
   ══════════════════════════════════════════════════════════════ */
.hidden  { display: none !important; }
.hidden-by-global-search { display: none !important; }
.flex    { display: flex; }
.gap-2   { gap: 8px; }
.gap-4   { gap: 16px; }
.mt-4    { margin-top: 16px; }
.mb-4    { margin-bottom: 16px; }
.text-right { text-align: right; }

/* ══════════════════════════════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════════════════════════════ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-main);
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤1024px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .topbar {
        padding: 0 12px;
        gap: 8px;
    }

    .logo-text h1 { font-size: 15px; }

    .nav-item {
        padding: 6px 10px;
        font-size: 12px;
    }
    .nav-item i { font-size: 15px; }

    .user-details { display: none; }

    .view-container {
        padding: 16px;
    }

    .dash-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-content {
        max-width: 100%;
        border-radius: var(--radius-md);
    }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (≤768px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root {
        --topbar-height: auto;
    }

    .topbar {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 12px;
        gap: 8px;
    }

    .topbar-logo {
        order: 1;
    }

    .topbar-actions {
        order: 2;
        margin-left: auto;
    }

    .topbar-nav {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        gap: 2px;
        border-top: 1px solid var(--border-color);
        padding-top: 8px;
    }

    .nav-item {
        padding: 6px 8px;
        font-size: 11px;
        gap: 4px;
    }

    .logo-text h1 { font-size: 14px; }

    .view-container {
        padding: 12px;
    }

    .view-header {
        flex-direction: column !important;
        gap: 10px !important;
        padding: 12px !important;
    }

    .search-bar {
        width: 100% !important;
    }

    .dash-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .dash-card {
        padding: 14px;
    }

    .dash-card .value {
        font-size: 22px;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .card {
        padding: 14px;
    }

    .modal-content {
        padding: 14px;
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
        border-radius: var(--radius-md);
    }

    .auth-card {
        padding: 20px 16px;
    }

    .table-container {
        max-height: calc(100vh - 260px);
        border-radius: var(--radius-md);
    }

    /* Topbar btn text hidden on mobile */
    #btn-theme-toggle span,
    #btn-logout span {
        display: none;
    }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Small Mobile (≤480px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .topbar-nav {
        overflow-x: auto;
    }

    .nav-item span {
        display: none;
    }

    .dash-grid {
        grid-template-columns: 1fr;
    }

    .dash-card .value {
        font-size: 20px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 12px;
    }
}
