:root {
    --purple-50:  #f5f3ff;
    --purple-100: #ede9fe;
    --purple-200: #ddd6fe;
    --purple-300: #c4b5fd;
    --purple-400: #a78bfa;
    --purple-500: #8b5cf6;
    --purple-600: #7c3aed;
    --purple-700: #6d28d9;
    --purple-800: #5b21b6;
    --purple-900: #4c1d95;

    --indigo-500: #6366f1;

    --gray-50:  #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    --success: #10b981;
    --danger:  #ef4444;
    --warning: #f59e0b;

    --radius:    12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow:    0 4px 12px rgba(76, 29, 149, 0.06);
    --shadow-lg: 0 20px 60px rgba(76, 29, 149, 0.15);

    --gradient: linear-gradient(135deg, var(--indigo-500) 0%, var(--purple-500) 100%);
}

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

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--purple-600); text-decoration: none; }
a:hover { color: var(--purple-700); }

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--gray-800); }

/* ======================== LOGIN ======================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient);
    padding: 24px;
}

.login-card {
    background: #fff;
    padding: 48px 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 4px;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 32px;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--gray-800);
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s;
}
.btn-google:hover {
    border-color: var(--purple-300);
    background: var(--purple-50);
    color: var(--gray-800);
}

.alert {
    background: #fef2f2;
    color: #991b1b;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 20px;
    text-align: left;
    border-left: 3px solid var(--danger);
}
.alert.success {
    background: #f0fdf4;
    color: #166534;
    border-left-color: var(--success);
}

.hint { margin-top: 24px; color: var(--gray-400); font-size: 12px; }

/* ======================== APP LAYOUT ======================== */
body.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid var(--gray-200);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transition: transform 0.25s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 24px;
    border-bottom: 1px solid var(--gray-100);
    margin-bottom: 16px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.5px;
    box-shadow: var(--shadow);
}

.brand-title { font-weight: 600; font-size: 15px; color: var(--gray-800); }
.brand-sub   { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--gray-600);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}
.nav-item:hover {
    background: var(--purple-50);
    color: var(--purple-700);
}
.nav-item.active {
    background: var(--gradient);
    color: #fff;
    box-shadow: var(--shadow);
}
.nav-item.active:hover { color: #fff; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { border-top: 1px solid var(--gray-100); padding-top: 16px; }

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
    background: var(--gray-50);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-fallback {
    background: var(--gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    text-transform: uppercase;
}

.user-meta { min-width: 0; flex: 1; }
.user-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-logout { font-size: 11px; color: var(--gray-500); }

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.main {
    flex: 1;
    margin-left: 260px;
    min-width: 0;
}

.topbar-mobile {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 10;
}

.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 0;
}
.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--gray-700);
    border-radius: 1px;
}

.content {
    padding: 32px 40px;
    max-width: 1100px;
    margin: 0 auto;
}

/* ======================== TYPO + COMMON ======================== */
h1, h2, h3 { color: var(--gray-900); font-weight: 600; }
h2 { font-size: 24px; margin-bottom: 4px; }
h3 { font-size: 16px; }
.page-sub { color: var(--gray-500); font-size: 14px; margin-bottom: 24px; }

.card {
    background: #fff;
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}
.card h3 { margin-bottom: 8px; }
.card p { color: var(--gray-600); font-size: 14px; }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.card-feature {
    background: #fff;
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    transition: all 0.15s;
}
.card-feature:hover {
    border-color: var(--purple-300);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}
.card-feature .icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--purple-100);
    color: var(--purple-700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 14px;
}
.card-feature h3 { margin-bottom: 6px; }
.card-feature p { color: var(--gray-500); font-size: 13px; margin-bottom: 14px; }

/* ======================== BUTTONS ======================== */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: var(--shadow);
}
.btn-primary:hover { color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-lg); }

.btn-secondary {
    background: #fff;
    color: var(--purple-700);
    border: 1px solid var(--purple-200);
}
.btn-secondary:hover { background: var(--purple-50); color: var(--purple-800); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }

/* ======================== FILTERS / FORMS ======================== */
.filters {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
    margin: 16px 0;
}
.filters label, .form-grid label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: var(--gray-500);
    gap: 6px;
    font-weight: 500;
}
.filters input, .filters select,
.form-grid input, .form-grid select, .form-grid textarea {
    padding: 9px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.filters input:focus, .filters select:focus,
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
    outline: none;
    border-color: var(--purple-400);
    box-shadow: 0 0 0 3px var(--purple-100);
}

.summary {
    background: var(--purple-50);
    color: var(--purple-900);
    padding: 14px 18px;
    border-radius: var(--radius);
    margin: 12px 0 16px;
    font-size: 14px;
    border-left: 3px solid var(--purple-500);
}
.summary strong { color: var(--purple-700); font-weight: 600; }

/* ======================== TABLE ======================== */
.table-wrap {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}
.table th, .table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13.5px;
    vertical-align: middle;
}
.table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-600);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}
.table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    white-space: nowrap;
}
.table td:first-child, .table th:first-child { padding-left: 14px; }
.table td:last-child, .table th:last-child  { padding-right: 14px; text-align: right; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--purple-50); }

.table td.vendor {
    line-height: 1.35;
    word-break: break-word;
}
.table td.desc {
    color: var(--gray-500);
    font-size: 12.5px;
    line-height: 1.35;
}

.table .pill {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    background: var(--purple-100);
    color: var(--purple-800);
    font-weight: 500;
    white-space: nowrap;
}

/* Larguras mais compactas para colunas conhecidas */
.table th.col-check { width: 32px; padding-right: 0; }
.table th.col-id    { width: 60px; }
.table th.col-date  { width: 92px; white-space: nowrap; }
.table td:nth-child(3) { white-space: nowrap; }  /* Data */

/* Em telas <1100px, esconde colunas extras pra tudo caber */
@media (max-width: 1100px) {
    .table .hide-md { display: none; }
}

/* ======================== FORM GRID ======================== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    background: #fff;
    padding: 28px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
}
.form-grid label.full, .form-grid .full { grid-column: 1 / -1; }

.form-grid textarea { resize: vertical; min-height: 80px; }

.hidden { display: none !important; }

.toggle {
    background: none;
    border: 1px solid var(--gray-200);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.toggle.on  { background: var(--purple-100); color: var(--purple-800); border-color: var(--purple-300); }
.toggle.off { color: var(--gray-500); }
.toggle:hover { filter: brightness(0.95); }

.bulk-bar {
    display: flex;
    align-items: center;
    gap: 10px 12px;
    background: var(--purple-50);
    border: 1px solid var(--purple-200);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 12px 0;
    font-size: 14px;
    flex-wrap: wrap;
}
.bulk-bar strong { color: var(--purple-700); }
.bulk-bar > span { flex: 0 0 auto; }
.bulk-bar button { flex: 1 1 auto; min-width: 200px; }
@media (min-width: 700px) {
    .bulk-bar button { flex: 0 0 auto; min-width: 0; }
}

/* Filter card v2 */
.filters-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.filter-block { display: flex; flex-direction: column; gap: 8px; }

.filter-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.pills input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.pill-toggle {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border: 1px solid var(--gray-200);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    user-select: none;
    transition: all 0.12s;
    background: #fff;
}
.pill-toggle:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}
.pills input:checked + .pill-toggle {
    background: var(--gradient);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}
.pills input:focus-visible + .pill-toggle {
    outline: 2px solid var(--purple-400);
    outline-offset: 2px;
}

.filter-inline {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.filter-inline label.inline {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    min-width: 160px;
}
.filter-inline label.inline select {
    padding: 9px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 14px;
    color: var(--gray-800);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}
.filter-inline label.inline select:focus {
    outline: none;
    border-color: var(--purple-400);
    box-shadow: 0 0 0 3px var(--purple-100);
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--gray-100);
    padding-top: 16px;
    margin-top: 4px;
    flex-wrap: wrap;
}

@media (max-width: 600px) {
    .filter-inline label.inline { min-width: 100%; }
    .filter-actions a[style*="margin-left:auto"] { margin-left: 0 !important; width: 100%; justify-content: center; }
}

/* ======================== CALENDAR ======================== */
.cal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}
.cal-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}
.cal-nav strong { padding: 0 12px; min-width: 160px; text-align: center; }

.cal-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
    margin: 8px 0 16px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.legend-dot  { width: 10px; height: 10px; border-radius: 50%; }
.legend-link { color: var(--gray-700); text-decoration: none; border-bottom: 1px dashed var(--gray-300); }
.legend-link:hover { color: var(--purple-700); border-color: var(--purple-300); }
.legend-action { margin-left: auto; font-size: 13px; }

.legend-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    padding: 5px 10px;
    border: 1px solid var(--gray-200);
    border-radius: 999px;
    text-decoration: none;
    color: var(--gray-700);
    transition: all 0.12s;
    cursor: pointer;
}
.legend-toggle:hover { border-color: var(--purple-300); }
.legend-toggle.on  { background: #fff; }
.legend-toggle.off { background: var(--gray-100); color: var(--gray-400); border-color: var(--gray-200); }
.legend-toggle.off .legend-dot { opacity: 0.35; }

.legend-edit {
    font-size: 14px;
    text-decoration: none;
    color: var(--gray-400);
    margin-right: 8px;
    margin-left: -4px;
}
.legend-edit:hover { color: var(--purple-700); }

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
    background: var(--gray-100);
    padding: 6px;
    border-radius: var(--radius);
}
.cal-weekday {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 0;
    background: transparent;
}

.cal-day {
    background: #fff;
    border-radius: 10px;
    padding: 8px 8px 10px;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    border: 1px solid transparent;
    transition: all 0.12s;
    position: relative;
}
.cal-day:hover { border-color: var(--purple-300); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.cal-day-empty { background: transparent; pointer-events: none; min-height: 0; }
.cal-day.today { background: var(--purple-50); border-color: var(--purple-300); }
.cal-day.holiday { background: #fff7ed; }

.cal-day-num {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
}
.cal-day.today .cal-day-num { color: var(--purple-700); }
.cal-holiday {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 12px;
}

.cal-day-children {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.child-pill {
    color: #fff;
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 999px;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.child-pill.is-override { box-shadow: 0 0 0 2px #fff, 0 0 0 3px currentColor; opacity: 0.95; }

@media (max-width: 700px) {
    .cal-day { min-height: 64px; padding: 6px; }
    .cal-day-num { font-size: 12px; }
    .child-pill { font-size: 9px; padding: 1px 5px; }
}

/* Cycle editor */
.cycle-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
    margin-top: 16px;
}
.cycle-day input[type="checkbox"] { display: none; }
.cycle-day-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 4px;
    border: 1.5px solid var(--gray-200);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.12s;
    background: #fff;
}
.cycle-day input:checked + .cycle-day-box {
    background: var(--gradient);
    border-color: transparent;
    color: #fff;
}
.cycle-day-wd { font-size: 10px; text-transform: uppercase; opacity: 0.7; letter-spacing: 0.5px; }
.cycle-day-num { font-size: 16px; font-weight: 600; margin-top: 2px; }

/* Day detail */
.day-group {
    background: var(--gray-50);
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 12px;
}
.day-group-header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

/* Mini button */
.mini-btn {
    background: #fff;
    border: 1px solid var(--gray-200);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.12s;
}
.mini-btn:hover { border-color: var(--purple-300); }
.mini-btn.on  { background: #ecfdf5; border-color: #10b981; }
.mini-btn.off { background: #fef2f2; border-color: #ef4444; }

.weekday-exceptions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.wd-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 12px;
    align-items: center;
    padding: 10px;
    background: var(--gray-50);
    border-radius: 10px;
}
.wd-name { color: var(--gray-700); }
.wd-note {
    grid-column: 1 / -1;
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13px;
}
.wd-note:focus {
    outline: none;
    border-color: var(--purple-400);
    box-shadow: 0 0 0 3px var(--purple-100);
}
@media (max-width: 600px) {
    .wd-row { grid-template-columns: 1fr; }
}

/* ======================== RESPONSIVE ======================== */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .main { margin-left: 0; }
    .topbar-mobile { display: flex; }
    .content { padding: 24px 16px; }
    .form-grid { grid-template-columns: 1fr; padding: 20px; }
    .table th, .table td { padding: 10px 12px; }
    .table .hide-sm { display: none; }
}
