/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}
.btn i { font-size: 16px; }
.btn i svg, .btn svg { width: 16px; height: 16px; }
.btn-primary { background: #ffffff; color: #09090b; border-color: #ffffff; }
.btn-primary:hover { background: #e4e4e7; border-color: #e4e4e7; }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--border-focus); }
.btn-ghost { background: transparent; color: #ffffff; border: none; padding: 8px 12px; }
.btn-ghost:hover { background: var(--accent-muted); color: #ffffff; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #16a34a; }
.btn-outline { background: transparent; color: var(--text-primary); border-color: var(--border); }
.btn-outline:hover { background: var(--accent-muted); border-color: var(--border-focus); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

/* ═══════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: var(--transition);
}
.card:hover { border-color: var(--border-focus); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════
   STAT CARDS
   ═══════════════════════════════════════════ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-focus); }
.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.stat-icon { font-size: 20px; color: var(--text-dim); }
.stat-icon svg { width: 20px; height: 20px; }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.2; }
.stat-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ═══════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════ */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th {
    text-align: left;
    padding: 14px 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    white-space: nowrap;
}
.data-table th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.data-table th:last-child { border-radius: 0 var(--radius-lg) 0 0; }

.data-table td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-light);
    font-size: 14px;
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--accent-muted); }
.data-table .text-right { text-align: right; }
.data-table .text-center { text-align: center; }
.data-table .text-mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; }

.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table-actions .btn-ghost { color: #a1a1aa; }
.table-actions .btn-ghost:hover { color: #ffffff; background: rgba(255,255,255,0.1); }

/* ═══════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════ */
.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 720px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-grid .form-group.full { grid-column: 1 / -1; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input, select, textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
    outline: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.05);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
textarea { resize: vertical; min-height: 80px; }
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2371717a' 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-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-light);
}

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.form-half { width: calc(50% - 8px); display: inline-block; vertical-align: top; }

/* ═══════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.badge-active { background: rgba(255,255,255,0.1); color: #ffffff; }
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-paid { background: var(--success-bg); color: var(--success); }
.badge-overdue { background: var(--danger-bg); color: var(--danger); }
.badge-invoiced { background: var(--info-bg); color: var(--info); }
.badge-paused { background: rgba(113,113,122,0.15); color: var(--text-muted); }
.badge-finished { background: rgba(113,113,122,0.15); color: var(--text-muted); }
.badge-cancelled { background: var(--danger-bg); color: var(--danger); }
.badge-fixed { background: rgba(99,102,241,0.15); color: #818cf8; }
.badge-variable { background: var(--warning-bg); color: var(--warning); }
.badge-draft { background: rgba(113,113,122,0.15); color: var(--text-muted); }
.badge-sent { background: var(--info-bg); color: var(--info); }
.badge-approved { background: var(--success-bg); color: var(--success); }
.badge-rejected { background: var(--danger-bg); color: var(--danger); }

/* ═══════════════════════════════════════════
   PAGE HEADER
   ═══════════════════════════════════════════ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.page-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

/* ═══════════════════════════════════════════
   MONTH SELECTOR
   ═══════════════════════════════════════════ */
.month-selector {
    display: flex;
    align-items: center;
    gap: 16px;
    justify-content: center;
    margin-bottom: 24px;
}
.month-label { font-size: 16px; font-weight: 700; min-width: 160px; text-align: center; }

/* ═══════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════ */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; display: block; color: var(--text-dim); }
.empty-state i svg { width: 48px; height: 48px; }
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 14px; margin-bottom: 20px; }

/* ═══════════════════════════════════════════
   FLASH MESSAGES
   ═══════════════════════════════════════════ */
.flash-messages { margin-bottom: 20px; }
.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    animation: flashIn 0.3s ease;
}
@keyframes flashIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.flash-error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.flash-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(234,179,8,0.2); }
.flash-close { background: none; border: none; color: inherit; opacity: 0.6; margin-left: auto; padding: 4px; }
.flash-close:hover { opacity: 1; }

/* ═══════════════════════════════════════════
   CHART CONTAINER
   ═══════════════════════════════════════════ */
.chart-container { position: relative; height: 300px; }

/* ═══════════════════════════════════════════
   ICON & COLOR PICKERS
   ═══════════════════════════════════════════ */
.icon-grid, .color-grid { display: flex; flex-wrap: wrap; gap: 6px; max-height: 240px; overflow-y: auto; padding: 4px; }
.icon-option {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-input); border: 2px solid var(--border);
    border-radius: var(--radius-sm); color: #ffffff;
    font-size: 16px; transition: var(--transition);
}
.icon-option svg { width: 18px; height: 18px; }
.icon-option:hover { border-color: var(--border-focus); background: rgba(255,255,255,0.08); }
.icon-option.selected { border-color: #ffffff; background: rgba(255,255,255,0.15); }

.icon-search {
    padding: 10px 14px;
    font-size: 13px;
}

.color-grid { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px; }
.color-option {
    width: 28px; height: 28px;
    border-radius: 50%; border: 3px solid transparent;
    transition: var(--transition); cursor: pointer;
}
.color-option:hover { transform: scale(1.15); }
.color-option.selected { border-color: #ffffff; transform: scale(1.2); box-shadow: 0 0 0 2px var(--bg-primary), 0 0 8px rgba(255,255,255,0.3); }

/* ═══════════════════════════════════════════
   DETAIL SECTIONS
   ═══════════════════════════════════════════ */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.detail-item { }
.detail-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.detail-value { font-size: 15px; font-weight: 600; }

.section-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ═══════════════════════════════════════════
   RESPONSIVE GRID
   ═══════════════════════════════════════════ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

@media (max-width: 768px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
    .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
    .page-header > div { width: 100%; display: flex; gap: 8px; flex-wrap: wrap; }
    .page-header .btn { flex: 1; justify-content: center; min-width: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
    .stat-label { font-size: 11px; }
    .card { padding: 14px; max-width: 100%; overflow-x: auto; }
    .card-header { flex-wrap: wrap; gap: 8px; }
    .form-card { padding: 16px; max-width: 100%; }
    .form-half { width: 100%; display: block; }
    .month-selector { gap: 6px; margin-bottom: 16px; flex-wrap: wrap; justify-content: center; }
    .month-label { font-size: 14px; min-width: auto; }
    .page-title { font-size: 20px; word-break: break-word; }
    .page-subtitle { font-size: 12px; }
    .section-title { font-size: 14px; flex-wrap: wrap; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }
    .detail-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .chart-container { height: 200px; }
    .empty-state { padding: 30px 12px; }
    .flash { padding: 10px 14px; font-size: 13px; }

    /* Tabelas */
    .table-wrapper { border-radius: var(--radius); -webkit-overflow-scrolling: touch; max-width: 100%; }
    .data-table { min-width: 600px; }
    .data-table th, .data-table td { padding: 10px 12px; font-size: 12px; white-space: nowrap; }
    .data-table th { font-size: 10px; }
    .table-actions { gap: 4px; }
    .table-actions .btn, .table-actions .btn-sm { padding: 4px 8px; font-size: 11px; }
    .table-actions .btn-ghost { padding: 4px; }

    .btn { padding: 8px 14px; font-size: 13px; }
    .btn-sm { padding: 5px 10px; font-size: 12px; }
    .badge { padding: 3px 8px; font-size: 10px; }

    /* Forçar conteúdo a não estourar */
    .main-content [style*="display:flex"], .main-content [style*="display: flex"] { flex-wrap: wrap !important; }
    .main-content [style*="margin-left:auto"], .main-content [style*="margin-left: auto"] { margin-left: 0 !important; width: 100% !important; }
    .main-content [style*="min-width:"] { min-width: 0 !important; }
    .main-content .stat-card[style] { flex: 1 1 auto !important; min-width: 0 !important; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 18px; }
    .detail-grid { grid-template-columns: 1fr; }
    .page-title { font-size: 18px; }
    .chart-container { height: 160px; }
    .data-table { min-width: 500px; }
    .main-content { padding: 10px 6px; }
}

.badge-received { background: rgba(113,113,122,0.15); color: var(--text-muted); }
.badge-diagnosing { background: rgba(99,102,241,0.15); color: #818cf8; }
.badge-waiting_approval { background: var(--warning-bg); color: var(--warning); }
.badge-approved { background: var(--success-bg); color: var(--success); }
.badge-in_progress { background: rgba(59,130,246,0.15); color: #3b82f6; }
.badge-testing { background: rgba(168,85,247,0.15); color: #a855f7; }
.badge-completed { background: var(--success-bg); color: var(--success); }
.badge-delivered { background: rgba(255,255,255,0.1); color: #ffffff; }
