:root {
    --black: #0b0b0c;
    --black-soft: #19191c;
    --gray-900: #222226;
    --gray-700: #47474d;
    --gray-500: #75757c;
    --gray-300: #b7b7bd;
    --gray-200: #dcdce0;
    --gray-100: #eeeef1;
    --gray-50: #f7f7f8;
    --white: #ffffff;
    --danger: #b3261e;
    --danger-bg: #fbeceb;
    --success: #1e7a34;
    --success-bg: #eaf6ec;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, .10);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font-sans);
    color: var(--black);
    background: var(--gray-50);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font-family: inherit; }

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

/* ---------- Auth (login / setup) ---------- */

.auth-body { background: var(--white); }

.auth-split { display: flex; min-height: 100vh; }

.auth-brand-panel {
    flex: 1 1 42%;
    background: var(--black);
    color: var(--white);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 64px;
    position: relative;
    overflow: hidden;
}

.auth-brand-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 18% 18%, rgba(255, 255, 255, .07), transparent 42%),
        repeating-linear-gradient(135deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 26px);
    pointer-events: none;
}

.auth-brand-content { position: relative; z-index: 1; }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: var(--white);
    color: var(--black);
    font-weight: 800;
    font-size: 20px;
    margin-bottom: 28px;
}

.brand-mark-lg { width: 64px; height: 64px; font-size: 24px; border-radius: 18px; }

.auth-brand-content h1 { font-size: 32px; font-weight: 800; margin: 0 0 12px; letter-spacing: -.01em; }
.auth-brand-content p { color: var(--gray-300); max-width: 320px; line-height: 1.6; margin: 0; }
.auth-copyright { color: var(--gray-500); font-size: 13px; position: relative; z-index: 1; margin: 0; }

.auth-form-panel {
    flex: 1 1 58%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: var(--white);
}

.auth-form-card { width: 100%; max-width: 400px; }
.auth-form-card h2 { font-size: 26px; font-weight: 700; margin: 0 0 8px; letter-spacing: -.01em; }
.auth-form-card > .muted { margin: 0 0 28px; }

/* ---------- Forms ---------- */

.form-group { margin-bottom: 18px; display: flex; flex-direction: column; gap: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

label { font-size: 13px; font-weight: 600; color: var(--gray-700); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"], select {
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-size: 14px;
    font-family: inherit;
    background: var(--white);
    color: var(--black);
    width: 100%;
    transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--black);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, .08);
}

.input-with-action { position: relative; display: flex; align-items: center; }
.input-with-action input { padding-right: 74px; }

.toggle-password {
    position: absolute;
    right: 6px;
    background: none;
    border: none;
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-500);
    cursor: pointer;
    padding: 6px 8px;
}
.toggle-password:hover { color: var(--black); }

.form-check label { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--black); }
.form-check input[type="checkbox"] { width: 16px; height: 16px; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: var(--radius-sm);
    padding: 12px 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease;
    text-decoration: none;
}

.btn-block { width: 100%; }
.btn-dark { background: var(--black); color: var(--white); }
.btn-dark:hover { background: var(--black-soft); box-shadow: var(--shadow-md); }
.btn-ghost { background: transparent; color: var(--gray-700); border-color: var(--gray-200); }
.btn-ghost:hover { border-color: var(--gray-500); color: var(--black); }
.btn-sm { padding: 9px 16px; font-size: 13px; }

/* ---------- Alerts ---------- */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 16px;
    transition: opacity .3s ease, transform .3s ease;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(179, 38, 30, .25); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(30, 122, 52, .2); }
.flash-stack .alert.is-hidden { opacity: 0; transform: translateY(-6px); }

/* ---------- App shell ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--black);
    color: var(--white);
    display: flex;
    flex-direction: column;
    padding: 28px 20px;
}

.sidebar-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 36px; }
.sidebar-brand .brand-mark { margin-bottom: 0; }
.brand-name { font-weight: 700; line-height: 1.25; font-size: 14px; }

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

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--gray-300);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background .15s ease, color .15s ease;
}
.nav-link:hover { background: rgba(255, 255, 255, .07); color: var(--white); }
.nav-link.active { background: var(--white); color: var(--black); font-weight: 700; }
.nav-icon { display: inline-flex; flex-shrink: 0; }
.nav-icon svg { display: block; }

.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, .1); padding-top: 16px; margin-top: 16px; }
.nav-link-muted { color: var(--gray-500); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 36px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-100);
}
.topbar-title { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.topbar-user { display: flex; align-items: center; gap: 12px; }

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--black);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.user-meta { display: flex; flex-direction: column; font-size: 13px; line-height: 1.35; }
.user-meta small { color: var(--gray-500); }

.content { padding: 32px 36px; flex: 1; }

/* ---------- Cards / panels ---------- */

.welcome-card {
    background: var(--black);
    color: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
}
.welcome-card h2 { margin: 0 0 8px; font-size: 22px; }
.welcome-card p { color: var(--gray-300); margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 30px; font-weight: 800; letter-spacing: -.01em; }
.stat-label { color: var(--gray-500); font-size: 13px; }

.panel {
    background: var(--white);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.panel-header h3 { margin: 0; font-size: 17px; }

/* ---------- Table ---------- */

.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-500);
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}
.data-table td { padding: 14px 12px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

.user-cell { display: flex; align-items: center; gap: 12px; }
.user-cell small { display: block; color: var(--gray-500); font-size: 12px; }

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--gray-900);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-dark { background: var(--black); color: var(--white); }
.badge-outline { background: var(--white); color: var(--gray-700); border: 1px solid var(--gray-200); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.dot-on { background: var(--success); }
.dot-off { background: var(--gray-300); }

.row-actions { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.inline-form { display: inline; }

.btn-icon {
    background: none;
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease;
}
.btn-icon:hover { border-color: var(--black); color: var(--black); }
.btn-icon-danger:hover { border-color: var(--danger); color: var(--danger); }

.empty-row { text-align: center; color: var(--gray-500); padding: 32px !important; }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 11, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
    z-index: 50;
    padding: 20px;
}
.modal-backdrop.is-open { opacity: 1; pointer-events: auto; }

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    transform: translateY(12px);
    transition: transform .18s ease;
}
.modal-backdrop.is-open .modal { transform: translateY(0); }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 26px;
    border-bottom: 1px solid var(--gray-100);
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--gray-500); }
.modal-close:hover { color: var(--black); }

.modal form { padding: 22px 26px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Upload / dropzone / progress ---------- */

.dropzone {
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius-md);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--black); background: var(--gray-50); }
.dropzone p { margin: 4px 0; }

.file-list-preview { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.file-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--gray-50);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 12.5px;
}
.file-chip button {
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}
.file-chip button:hover { color: var(--danger); }

.progress-bar {
    height: 8px;
    background: var(--gray-100);
    border-radius: 999px;
    overflow: hidden;
    margin: 10px 0;
}
.progress-bar-fill {
    height: 100%;
    background: var(--black);
    border-radius: 999px;
    transition: width .3s ease;
}

.batch-card {
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    margin-bottom: 14px;
}
.batch-card:last-child { margin-bottom: 0; }
.batch-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.batch-summary { font-size: 13px; color: var(--gray-500); font-weight: 600; }

.batch-items { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.batch-item-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; padding: 6px 0; border-top: 1px solid var(--gray-50); }
.batch-item-row:first-child { border-top: none; }
.batch-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-item-status { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.status-pending { background: var(--gray-100); color: var(--gray-700); }
.status-removing_bg, .status-formatting { background: #fff6e0; color: #8a6100; }
.status-done { background: var(--success-bg); color: var(--success); }
.status-failed { background: var(--danger-bg); color: var(--danger); }
.batch-item-outputs { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Tabs / Galeria ---------- */

.tabs-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.tab-btn {
    background: var(--white);
    color: var(--gray-700);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
}
.tab-btn:hover { border-color: var(--black); color: var(--black); }
.tab-btn.active { background: var(--black); color: var(--white); border-color: var(--black); }

.gallery-subfilter {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: -8px 0 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-100);
}
.tab-btn-sub { padding: 6px 12px; font-size: 12px; background: var(--gray-50); border-color: var(--gray-100); color: var(--gray-700); }
.tab-btn-sub.active { background: var(--gray-900); border-color: var(--gray-900); color: var(--white); }
.tab-btn-sub:hover { border-color: var(--gray-700); }

.gallery-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.gallery-search {
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font-size: 13.5px;
    font-family: inherit;
    min-width: 240px;
}
.gallery-search:focus { outline: none; border-color: var(--black); box-shadow: 0 0 0 3px rgba(0,0,0,.08); }

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.gallery-thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--gray-50);
    border: 1px solid var(--gray-100);
    cursor: pointer;
}
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s ease; }
.gallery-thumb:hover img { transform: scale(1.05); }
.gallery-thumb-caption {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,.72), transparent);
    color: var(--white);
    font-size: 11px;
    padding: 16px 8px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: opacity .15s ease;
}
.gallery-thumb:hover .gallery-thumb-caption { opacity: 1; }

.lightbox {
    background: transparent;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}
.lightbox img { max-width: 92vw; max-height: 80vh; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); background: var(--white); }
.lightbox-caption { color: var(--white); margin-top: 12px; font-size: 13px; text-align: center; }
.lightbox-close {
    position: absolute;
    top: -44px;
    right: 0;
    background: rgba(255,255,255,.12);
    color: var(--white);
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 50%;
    width: 34px;
    height: 34px;
}

/* ---------- Histórico ---------- */

.history-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}
.history-filters select,
.history-filters input[type="date"] { width: auto; padding: 9px 12px; font-size: 13px; }
.history-filters .gallery-search { min-width: 200px; flex: 1 1 200px; }

.history-thumb {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--gray-50);
    border: 1px solid var(--gray-100);
    display: block;
}

.history-outputs { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
    .auth-brand-panel { display: none; }
}

@media (max-width: 860px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 16px 20px; }
    .sidebar-brand { margin-bottom: 0; }
    .sidebar-nav { flex-direction: row; flex: 1; justify-content: flex-end; }
    .sidebar-footer { border-top: none; padding-top: 0; margin-top: 0; }
    .brand-name { display: none; }
    .content { padding: 20px; }
    .topbar { padding: 16px 20px; }
    .stat-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
}
