/* ============================================
   ANGOCONTA - Sistema SaaS de Contabilidade
   Estilos Principais (100% Responsivo)
   ============================================ */

:root {
    --primary: #059669;
    --primary-dark: #047857;
    --primary-light: #d1fae5;
    --secondary: #6366f1;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0891b2;
    --dark: #1e293b;
    --light: #f8fafc;
    --gray: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --sidebar-collapsed: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--light);
    color: var(--dark);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ============================================
   LAYOUT
   ============================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: #fff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease, width 0.3s ease;
    will-change: transform, width;
    overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    flex-shrink: 0;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--dark);
    min-width: 0;
    overflow: hidden;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 14px;
    flex-shrink: 0;
}

.brand-text {
    font-size: 18px;
    font-weight: 700;
    transition: opacity 0.3s, width 0.3s;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .brand-text { opacity: 0; width: 0; }

.toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--gray);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.nav-section { margin-bottom: 8px; }

.nav-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--gray);
    padding: 8px 12px 4px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.sidebar.collapsed .nav-label { display: none; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--gray);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    margin-bottom: 2px;
    white-space: nowrap;
}

.nav-link:hover,
.nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-text { transition: opacity 0.3s; }
.sidebar.collapsed .nav-text { display: none; }

/* User area */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
}

.user-details { flex: 1; min-width: 0; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--gray); text-transform: capitalize; }
.sidebar.collapsed .user-details { display: none; }

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px 32px;
    transition: margin-left 0.3s ease;
    min-width: 0;
    width: 100%;
}

.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-collapsed); }

/* Mobile header */
.mobile-header {
    display: none;
    align-items: center;
    gap: 12px;
    margin: -24px -32px 20px;
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--dark);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--dark);
}

/* Sidebar overlay para mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 999;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* ============================================
   PAGE HEADER
   ============================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title { font-size: 28px; font-weight: 700; line-height: 1.2; }
.page-subtitle { color: var(--gray); font-size: 14px; margin-top: 4px; }

/* ============================================
   CARDS
   ============================================ */
.card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.card-body { padding: 20px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

/* ============================================
   STATS
   ============================================ */
.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.green { background: var(--primary-light); color: var(--primary); }
.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.amber { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }
.stat-icon.cyan { background: #cffafe; color: #0891b2; }

.stat-value { font-size: 24px; font-weight: 700; word-break: break-word; }
.stat-label { font-size: 13px; color: var(--gray); margin-top: 2px; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    touch-action: manipulation;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
    background: white;
    border: 1px solid var(--border);
    color: var(--dark);
}
.btn-outline:hover { background: var(--light); }

.btn-danger { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon { padding: 8px; }

/* ============================================
   TABLES
   ============================================ */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 600px;
}
.table thead th {
    background: #f8fafc;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--gray);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
.badge-green { background: var(--primary-light); color: var(--primary); }
.badge-amber { background: #fef3c7; color: #d97706; }
.badge-red { background: #fee2e2; color: var(--danger); }
.badge-blue { background: #dbeafe; color: #2563eb; }
.badge-gray { background: #f1f5f9; color: var(--gray); }

/* ============================================
   FORMS
   ============================================ */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--dark);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
select.form-control {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* Search */
.search-box {
    position: relative;
    max-width: 360px;
    width: 100%;
}
.search-box input {
    padding-left: 40px;
    width: 100%;
}
.search-box svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray);
    width: 16px;
    height: 16px;
    pointer-events: none;
}

/* Filters bar */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 20px;
}

/* ============================================
   AUTH PAGES
   ============================================ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 50%, #a7f3d0 100%);
    padding: 20px;
}

.auth-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 440px;
    padding: 40px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

/* ============================================
   DRE
   ============================================ */
.dre-result {
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}
.dre-result.lucro { background: #ecfdf5; border: 1px solid #a7f3d0; }
.dre-result.prejuizo { background: #fef2f2; border: 1px solid #fecaca; }

.dre-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    gap: 12px;
    flex-wrap: wrap;
}
.dre-line.destaque { font-weight: 700; border-top: 2px solid var(--border); margin-top: 8px; padding-top: 12px; }
.dre-line.sub { padding-left: 20px; font-size: 13px; color: var(--gray); }

/* ============================================
   ALERTS
   ============================================ */
.alert {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
    word-wrap: break-word;
}
.alert-success { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}
.modal-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.modal-body { padding: 24px; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray);
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}
.modal-close:hover { background: var(--light); }

/* ============================================
   RESPONSIVE - TABLET (max-width: 1024px)
   ============================================ */
@media (max-width: 1024px) {
    .main-content {
        padding: 20px 24px;
    }
    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
    .page-title { font-size: 24px; }
}

/* ============================================
   RESPONSIVE - MOBILE (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    html { font-size: 15px; }

    /* Sidebar vira drawer */
    .sidebar {
        transform: translateX(-100%);
        width: 280px !important;
        max-width: 85vw;
        box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar.collapsed {
        width: 280px !important;
    }
    .sidebar.collapsed .nav-text,
    .sidebar.collapsed .nav-label,
    .sidebar.collapsed .user-details,
    .sidebar.collapsed .brand-text {
        display: block;
        opacity: 1;
        width: auto;
    }
    .sidebar.collapsed .brand-text { opacity: 1; width: auto; }

    /* Overlay */
    .sidebar.open ~ .sidebar-overlay {
        display: block;
    }

    /* Main content sem margin */
    .main-content {
        margin-left: 0 !important;
        padding: 0;
        min-height: 100vh;
    }

    /* Mobile header visível */
    .mobile-header {
        display: flex;
        margin: 0 0 16px 0;
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 50;
    }

    /* Page header */
    .page-header {
        flex-direction: column;
        gap: 12px;
        margin-bottom: 20px;
        padding: 0 16px;
    }
    .page-title { font-size: 22px; }
    .page-subtitle { font-size: 13px; }

    /* Cards em 1 coluna */
    .card-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 0 16px;
    }

    .stat-card {
        padding: 16px;
    }
    .stat-value { font-size: 20px; }
    .stat-icon { width: 36px; height: 36px; }
    .stat-icon svg { width: 18px; height: 18px; }

    /* Cards de acesso rápido */
    .card-grid > a.card {
        padding: 16px !important;
    }

    /* Tabelas */
    .table-wrap {
        margin: 0 16px;
        border-radius: 10px;
    }
    .table {
        font-size: 13px;
        min-width: 500px;
    }
    .table thead th,
    .table tbody td {
        padding: 10px 12px;
    }

    /* Botões */
    .btn {
        padding: 10px 16px;
        font-size: 13px;
        width: 100%;
    }
    .page-header .btn {
        width: auto;
    }
    .btn-sm { padding: 6px 12px; font-size: 12px; }

    /* Formulários */
    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }
    .form-group { margin-bottom: 14px; }
    .form-control {
        padding: 12px 14px;
        font-size: 16px; /* Evita zoom no iOS */
    }

    /* Filtros */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 14px 16px;
        margin: 0 16px 16px;
    }
    .filters-bar .form-group,
    .filters-bar .btn {
        width: 100%;
        margin: 0;
    }

    /* Search */
    .search-box {
        max-width: 100%;
    }

    /* Auth */
    .auth-card {
        padding: 28px 20px;
        border-radius: 12px;
    }
    .auth-logo { margin-bottom: 24px; }

    /* DRE */
    .dre-result { padding: 16px; }
    .dre-line { font-size: 13px; }
    .dre-line.sub { padding-left: 12px; }

    /* Modal */
    .modal-overlay {
        padding: 12px;
        align-items: flex-end;
    }
    .modal-content {
        border-radius: 12px 12px 0 0;
        max-height: 85vh;
    }
    .modal-header,
    .modal-body {
        padding: 16px 20px;
    }

    /* Alerts */
    .alert {
        margin: 0 16px 16px;
        padding: 12px 14px;
        font-size: 13px;
    }

    /* Badges */
    .badge {
        padding: 3px 8px;
        font-size: 11px;
    }

    /* Card body/header */
    .card-header,
    .card-body {
        padding: 14px 16px;
    }
}

/* ============================================
   RESPONSIVE - SMALL MOBILE (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    html { font-size: 14px; }

    .page-title { font-size: 20px; }
    .stat-value { font-size: 18px; }

    .mobile-header {
        padding: 10px 12px;
    }

    .card-grid,
    .table-wrap,
    .filters-bar,
    .page-header,
    .alert {
        margin-left: 12px;
        margin-right: 12px;
    }

    .main-content {
        padding: 0;
    }

    .btn {
        padding: 10px 14px;
    }

    .auth-card {
        padding: 24px 16px;
    }
}

/* ============================================
   UTILITY
   ============================================ */
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-mono { font-family: 'SF Mono', monospace; font-size: 13px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-4 { gap: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none; }

/* Touch-friendly utilities */
@media (hover: none) {
    .nav-link:hover { background: transparent; color: var(--gray); }
    .nav-link.active:hover { background: var(--primary-light); color: var(--primary); }
    .btn:hover { filter: none; }
    .btn:active { transform: scale(0.98); }
}