/* ============================================================
   TAGMAX Sistema - Cupertino Design System
   ============================================================ */

:root {
    --bg: #f5f5f7;
    --bg-elevated: #ffffff;
    --bg-sidebar: #fbfbfd;
    --bg-hover: #f0f0f3;
    --bg-active: #e8e8ed;

    --border: #d2d2d7;
    --border-strong: #b7b7be;
    --border-subtle: #e5e5ea;

    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #86868b;
    --text-inverse: #ffffff;

    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-active: #0062c4;
    --accent-soft: #e8f1fd;

    --success: #248a3d;
    --success-soft: #d8f2dd;
    --warning: #b25000;
    --warning-soft: #fff1d6;
    --danger: #d70015;
    --danger-soft: #ffe5e8;
    --neutral-soft: #ececef;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.10), 0 4px 8px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.14);

    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    --sidebar-width: 248px;
    --topbar-height: 56px;

    --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   Reset e base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 28px; letter-spacing: -0.02em; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }

p { margin: 0 0 12px 0; }
hr { border: 0; border-top: 1px solid var(--border-subtle); margin: 20px 0; }

::selection { background: var(--accent-soft); color: var(--text); }

/* ============================================================
   Layout principal
   ============================================================ */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    padding: 18px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 18px 10px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 12px;
}

.sidebar-brand img { width: 28px; height: 28px; object-fit: contain; }
.sidebar-brand .brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.nav-section {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 14px 12px 6px 12px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition);
}
.nav-link:hover { background: var(--bg-hover); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.nav-link.active .icon { opacity: 1; }

.sidebar-footer {
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid var(--border-subtle);
    font-size: 12px;
    color: var(--text-tertiary);
}

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

.topbar {
    height: var(--topbar-height);
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-title { font-size: 15px; font-weight: 600; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-pill);
    background: var(--bg-hover);
}
.user-chip .avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--text-inverse);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
}

.content {
    padding: 28px 32px 56px 32px;
    max-width: 1280px;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}
.page-header h1 { margin: 0; }
.page-header .subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; }
.card + .card { margin-top: 16px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}
.stat-card .label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stat-card .value {
    font-size: 30px;
    font-weight: 600;
    margin-top: 6px;
    letter-spacing: -0.02em;
    color: var(--text);
}
.stat-card .delta { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }

/* ============================================================
   Botoes
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), border var(--transition), transform var(--transition);
    text-decoration: none;
    line-height: 1.4;
    font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--text-inverse); }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn-primary:active { background: var(--accent-active); }

.btn-secondary { background: var(--bg-elevated); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); text-decoration: none; }

.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--bg-hover); text-decoration: none; }

.btn-danger { background: var(--danger); color: var(--text-inverse); }
.btn-danger:hover { background: #b80012; text-decoration: none; }

.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 24px; font-size: 15px; border-radius: var(--radius-md); }
.btn-block { width: 100%; }

.btn-group { display: inline-flex; gap: 8px; }

/* ============================================================
   Formularios
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.input, .select, .textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    transition: border var(--transition), box-shadow var(--transition);
    line-height: 1.4;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.18);
}
.textarea { min-height: 80px; resize: vertical; }
.help-text { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.error-text { font-size: 12.5px; color: var(--danger); margin-top: 4px; }

.input-with-icon { position: relative; }
.input-with-icon .input { padding-left: 36px; }
.input-with-icon .icon-leading {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    width: 16px;
    height: 16px;
    pointer-events: none;
}

/* ============================================================
   Tabelas
   ============================================================ */
.table-wrapper {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.table thead th {
    text-align: left;
    padding: 11px 16px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg);
    border-bottom: 1px solid var(--border-subtle);
}
.table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-hover); }
.table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table .row-actions .btn-sm { padding: 4px 9px; font-size: 12px; }

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.table-toolbar .filters { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.4;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--neutral-soft); color: var(--text-secondary); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 160ms ease-out;
}
.modal {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: min(440px, 92vw);
    padding: 28px;
    animation: scaleIn 160ms cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-header { margin-bottom: 14px; }
.modal-header h3 { font-size: 17px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

/* ============================================================
   Alerts / Flash
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    margin-bottom: 16px;
    border: 1px solid transparent;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.alert-success { background: var(--success-soft); color: var(--success); border-color: rgba(36, 138, 61, 0.2); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: rgba(215, 0, 21, 0.2); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: rgba(178, 80, 0, 0.2); }
.alert-info { background: var(--accent-soft); color: var(--accent); border-color: rgba(0, 113, 227, 0.2); }

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-secondary);
}
.empty-state .icon { font-size: 32px; opacity: 0.4; margin-bottom: 12px; }
.empty-state h3 { color: var(--text); margin-bottom: 8px; }
.empty-state p { margin: 0; font-size: 13.5px; }

/* ============================================================
   Pagina de login
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    background:
      radial-gradient(circle at 25% 15%, rgba(0, 113, 227, 0.10), transparent 45%),
      radial-gradient(circle at 80% 80%, rgba(99, 230, 203, 0.10), transparent 45%),
      var(--bg);
}
.login-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 40px 36px;
    width: min(420px, 100%);
}
.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 28px;
}
.login-brand img { width: 56px; height: 56px; margin-bottom: 12px; }
.login-brand h1 { font-size: 22px; }
.login-brand .tagline { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

/* ============================================================
   File upload (drag drop)
   ============================================================ */
.file-drop {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 24px;
    text-align: center;
    background: var(--bg);
    transition: border var(--transition), background var(--transition);
    cursor: pointer;
}
.file-drop:hover, .file-drop.dragging {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.file-drop input[type="file"] { display: none; }
.file-drop .file-icon { font-size: 32px; opacity: 0.4; margin-bottom: 10px; }
.file-drop .file-hint { color: var(--text-secondary); font-size: 13px; margin-top: 6px; }

.file-selected {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--accent-soft);
    border-radius: var(--radius-md);
    margin-top: 12px;
    font-size: 13.5px;
}
.file-selected .file-name { flex: 1; font-weight: 500; }
.file-selected .file-size { color: var(--text-secondary); font-size: 12px; }

/* ============================================================
   Detail rows / kv
   ============================================================ */
.detail-list { display: flex; flex-direction: column; gap: 10px; }
.detail-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 16px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
}
.detail-row:last-child { border-bottom: none; }
.detail-row dt { font-size: 13px; color: var(--text-secondary); margin: 0; }
.detail-row dd { margin: 0; font-size: 13.5px; font-family: var(--font-mono); word-break: break-all; }

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
}
.toast {
    background: rgba(29, 29, 31, 0.95);
    color: var(--text-inverse);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 200ms ease-out;
    max-width: 360px;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   Utilitarios
   ============================================================ */
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-mono { font-family: var(--font-mono); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

.hidden { display: none !important; }

/* ============================================================
   Responsivo
   ============================================================ */
@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 280px;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform var(--transition);
    }
    .sidebar.open { transform: translateX(0); }
    .topbar .menu-toggle { display: inline-flex; }
    .form-row { grid-template-columns: 1fr; }
    .content { padding: 18px; }
    .detail-row { grid-template-columns: 1fr; gap: 4px; }
}
@media (min-width: 901px) {
    .menu-toggle { display: none; }
}
