:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --muted: #6b7280;
    --bg: #f4f5f7;
    --card-bg: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}

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

h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.2rem; margin: 24px 0 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }

/* --- Topbar / Sidebar --- */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; }

.sidebar {
    position: fixed;
    top: 57px;
    left: 0;
    bottom: 0;
    width: 220px;
    background: #111827;
    padding: 16px 0;
    overflow-y: auto;
    z-index: 15;
}
.sidebar a {
    display: block;
    padding: 12px 20px;
    color: #d1d5db;
    font-size: 0.95rem;
}
.sidebar a:hover { background: #1f2937; text-decoration: none; color: #fff; }

.content {
    margin-left: 220px;
    padding: 24px;
    max-width: 1200px;
}

@media (max-width: 900px) {
    .menu-toggle { display: block; }
    .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; width: 240px; }
    .sidebar.open { transform: translateX(0); }
    .content { margin-left: 0; padding: 16px; }
}

/* --- Login --- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(135deg, #1d4ed8, #111827);
}
.login-box {
    background: #fff; padding: 32px; border-radius: var(--radius);
    width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-box h1 { text-align: center; margin-bottom: 4px; }
.login-box .subtitle { text-align: center; color: var(--muted); margin-bottom: 20px; }

/* --- Forms --- */
label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 0.9rem; }
input[type=text], input[type=password], input[type=email], input[type=date],
input[type=number], textarea, select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 0.95rem; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-top: 16px; }
.checkbox-label input { width: auto; }

.form-card, .panel {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; max-width: 620px;
}
.panel { max-width: none; }

.form-actions { margin-top: 20px; display: flex; gap: 10px; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin-left: 6px; }

/* --- Buttons --- */
.btn {
    display: inline-block; padding: 10px 16px; border-radius: 8px;
    border: 1px solid transparent; font-size: 0.9rem; font-weight: 600;
    cursor: pointer; text-align: center;
}
.btn:hover { text-decoration: none; opacity: 0.92; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }

/* --- Alerts --- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-warning { background: #fef3c7; color: #92400e; }

/* --- Cards --- */
.cards-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px; margin-bottom: 24px;
}
.cards-grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; display: flex; flex-direction: column; gap: 6px;
}
.card-link { color: var(--text); }
.card-link:hover { text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.card-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.card-value { font-size: 1.5rem; font-weight: 700; }
.card-desc { font-size: 0.85rem; color: var(--muted); }
.card-warning .card-value { color: var(--warning); }
.card-danger .card-value { color: var(--danger); }
.card-success .card-value { color: var(--success); }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.9rem; }
.table th { background: #f9fafb; font-weight: 700; }
.text-right { text-align: right; }
.valor-compra { color: var(--danger); font-weight: 600; }
.valor-pagamento { color: var(--success); font-weight: 600; }

/* --- Search --- */
.search-box input { max-width: 420px; font-size: 1rem; padding: 12px 14px; }
.empty { color: var(--muted); padding: 16px 0; }

/* --- Client page --- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.client-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; }
.saldo-box { padding: 16px 20px; border-radius: var(--radius); text-align: right; min-width: 200px; }
.saldo-box span { display: block; font-size: 0.8rem; color: var(--muted); }
.saldo-box strong { font-size: 1.8rem; }
.saldo-devedor { background: #fee2e2; }
.saldo-devedor strong { color: var(--danger); }
.saldo-quitado { background: #dcfce7; }
.saldo-quitado strong { color: var(--success); }
.saldo-inline strong { color: var(--danger); }

.action-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge-muted { background: #e5e7eb; color: #374151; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* --- Timeline --- */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item {
    display: grid; grid-template-columns: 100px 1fr auto auto;
    align-items: center; gap: 12px; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px;
}
.timeline-compra { border-left: 4px solid var(--danger); }
.timeline-pagamento { border-left: 4px solid var(--success); }
.timeline-date { font-size: 0.85rem; color: var(--muted); }
.timeline-tag { font-weight: 700; margin-right: 8px; }
.timeline-actions a { margin-left: 8px; font-size: 0.85rem; }
@media (max-width: 700px) {
    .timeline-item { grid-template-columns: 1fr; text-align: left; }
}

/* --- Vendas form --- */
.total-venda { margin: 14px 0; font-size: 1.1rem; }
.btn-remove-item { background: none; border: none; color: var(--danger); font-size: 1.2rem; cursor: pointer; }

/* --- Filters --- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.filter-bar select, .filter-bar input { width: auto; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }

.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

.muted { color: var(--muted); }

pre { background: #f3f4f6; padding: 12px; border-radius: 8px; overflow-x: auto; }
