/* ==========================================================================
   ESTOQUE — folha de estilo única do sistema
   Visual clean: fundo neutro, superfícies brancas, borda sutil no lugar de
   sombra pesada, azul apenas como cor de ação.
   ========================================================================== */

/* --------------------------------------------------------------- Tokens -- */
:root {
    --bg:            #f6f7f9;
    --surface:       #ffffff;
    --surface-soft:  #fafbfc;
    --border:        #e6e8ec;
    --border-strong: #d3d7de;

    --text:          #16191f;
    --text-muted:    #667085;
    --text-soft:     #98a2b3;

    --accent:        #2563eb;
    --accent-hover:  #1d4ed8;
    --accent-soft:   #eff4ff;
    --accent-border: #c7d7fe;

    --success:       #15803d;
    --success-soft:  #f0fdf4;
    --success-border:#bbf7d0;

    --warning:       #b45309;
    --warning-soft:  #fffbeb;
    --warning-border:#fde68a;

    --danger:        #b42318;
    --danger-soft:   #fef3f2;
    --danger-border: #fecdca;

    --radius:    10px;
    --radius-sm: 8px;
    --radius-lg: 14px;

    --shadow:    0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.07);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;

    --header-height: 60px;
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-right:  env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left, 0px);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    padding: 0 0 calc(var(--safe-bottom) + 16px) 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, figure { margin: 0; }

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

/* --------------------------------------------------------------- Header -- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: var(--safe-top);
}

.app-header nav {
    display: flex;
    align-items: center;
    gap: 24px;
    max-width: 1320px;
    margin: 0 auto;
    padding: 0 24px;
    height: var(--header-height);
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--text);
    text-transform: uppercase;
    white-space: nowrap;
}
.app-logo:hover { text-decoration: none; }
.app-logo-mark {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    letter-spacing: 0;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
    min-width: 0;
}

.app-nav a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.app-nav a:hover {
    background: var(--surface-soft);
    color: var(--text);
    text-decoration: none;
}
.app-nav a.is-active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.nav-count {
    display: inline-grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--warning-soft);
    border: 1px solid var(--warning-border);
    color: var(--warning);
    font-size: 0.68rem;
    font-weight: 700;
}

.app-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 16px;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}
.app-user-avatar {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.app-user-name {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text);
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-user-exit {
    color: var(--text-soft);
    font-size: 0.84rem;
    font-weight: 500;
}
.app-user-exit:hover { color: var(--danger); text-decoration: none; }

.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}
.nav-toggle span {
    display: block;
    width: 16px;
    height: 1.5px;
    background: currentColor;
    box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor;
}

.mobile-nav {
    display: none;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 8px 16px calc(16px + var(--safe-bottom));
}
.mobile-nav.open { display: block; }
.mobile-nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.mobile-nav a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 500;
}
.mobile-nav a:hover { background: var(--surface-soft); text-decoration: none; }
.mobile-nav a.is-active { background: var(--accent-soft); color: var(--accent); }
.mobile-nav .exit { color: var(--danger); }

/* ----------------------------------------------------------------- Main -- */
main {
    max-width: 1320px;
    margin: 0 auto;
    padding: 28px max(24px, var(--safe-right)) calc(40px + var(--safe-bottom)) max(24px, var(--safe-left));
}

/* -------------------------------------------------------------- Títulos -- */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}
.page-title {
    font-size: 1.4rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--text);
}
.page-subtitle {
    margin-top: 4px;
    font-size: 0.88rem;
    color: var(--text-muted);
}
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------- Cartão -- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card-title {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text);
}
.card-desc {
    margin-top: 2px;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }
.card-foot {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-soft);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Compatibilidade: <section> continua sendo um cartão */
main > section,
main > form > section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}

/* ----------------------------------------------------- Cartões de número -- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
a.stat:hover {
    border-color: var(--accent-border);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    text-decoration: none;
}
.stat-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stat-value {
    margin-top: 10px;
    font-size: 1.85rem;
    font-weight: 650;
    letter-spacing: -0.03em;
    color: var(--text);
    line-height: 1.1;
}
.stat-sub {
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-soft);
}
.stat-sub.is-danger  { color: var(--danger); font-weight: 500; }
.stat-sub.is-warning { color: var(--warning); font-weight: 500; }
.stat-sub.is-success { color: var(--success); font-weight: 500; }

/* -------------------------------------------------------------- Botões --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.86rem;
    font-weight: 550;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-soft); border-color: var(--text-soft); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-soft); color: var(--text); }

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

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.93); }

.btn-sm { min-height: 30px; padding: 0 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* ------------------------------------------------------------ Formulário -- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.field { display: grid; gap: 6px; }
.field-wide { grid-column: 1 / -1; }

label, .label {
    font-size: 0.82rem;
    font-weight: 550;
    color: var(--text);
}
.hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

input[type="text"], input[type="number"], input[type="password"], input[type="email"],
input[type="date"], input[type="datetime-local"], input[type="search"], input[type="tel"],
select, textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-soft); }
input:disabled, select:disabled, textarea:disabled {
    background: var(--surface-soft);
    color: var(--text-soft);
    cursor: not-allowed;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23667085' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 30px;
}

input[type="checkbox"], input[type="radio"] {
    width: 16px;
    height: 16px;
    min-height: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
}

/* Barra de filtros / busca */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.toolbar .grow { flex: 1; min-width: 220px; }

.search {
    position: relative;
    flex: 1;
    min-width: 220px;
}
.search input {
    padding-left: 34px;
}
.search::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 50%;
    width: 13px;
    height: 13px;
    margin-top: -6.5px;
    background: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cg fill='none' stroke='%2398a2b3' stroke-width='1.6'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5' stroke-linecap='round'/%3E%3C/g%3E%3C/svg%3E") no-repeat center / contain;
    pointer-events: none;
}

/* --------------------------------------------------------------- Tabela -- */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}
thead th {
    padding: 10px 14px;
    background: var(--surface-soft);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-soft); }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.cell-strong { font-weight: 550; }
.cell-muted { color: var(--text-muted); }

/* Tabela ocupando o cartão inteiro, sem padding lateral duplicado */
.card-body.flush thead th:first-child,
.card-body.flush tbody td:first-child { padding-left: 20px; }
.card-body.flush thead th:last-child,
.card-body.flush tbody td:last-child { padding-right: 20px; }

/* Compatibilidade com o markup antigo */
.table_component { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* --------------------------------------------------------------- Badges -- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface-soft);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 550;
    white-space: nowrap;
}
.badge-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.badge-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  border-color: var(--danger-border);  color: var(--danger); }
.badge-info    { background: var(--accent-soft);  border-color: var(--accent-border);  color: var(--accent); }
.badge-neutral { background: var(--surface-soft); border-color: var(--border);         color: var(--text-muted); }
.badge-pill { border-radius: 20px; }

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

/* -------------------------------------------------------------- Alertas -- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--text);
    font-size: 0.87rem;
    margin-bottom: 18px;
}
.alert strong { font-weight: 600; }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  border-color: var(--danger-border);  color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.alert-info    { background: var(--accent-soft);  border-color: var(--accent-border);  color: var(--accent); }

/* --------------------------------------------------------------- Vazio --- */
.empty {
    padding: 44px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty-title { font-size: 0.95rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-desc { font-size: 0.86rem; }

/* ---------------------------------------------------------------- Modal -- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(16, 24, 40, 0.45);
    backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
    width: min(560px, 100%);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
    border: none;
    background: transparent;
    color: var(--text-soft);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}
.modal-close:hover { background: var(--surface-soft); color: var(--text); }
.modal-body { padding: 20px; }
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------ Utilitários -- */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.row-between { justify-content: space-between; }
.stack { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }
.small { font-size: 0.8rem; }
.strong { font-weight: 600; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.divider { height: 1px; background: var(--border); border: none; margin: 18px 0; }
.hidden { display: none !important; }

/* -------------------------------------------------------- Banner do PWA -- */
.pwa-banner {
    position: fixed;
    right: 20px;
    bottom: calc(20px + var(--safe-bottom));
    z-index: 1600;
    width: min(360px, calc(100vw - 24px));
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.pwa-banner.open { display: block; }
.pwa-banner-content { padding: 16px; display: grid; gap: 12px; }
.pwa-banner-title { font-size: 0.9rem; font-weight: 600; }
.pwa-banner-text { font-size: 0.82rem; color: var(--text-muted); }
.pwa-banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pwa-banner-actions .btn { flex: 1 1 130px; }

/* ------------------------------------------------------------ Responsivo -- */
@media (max-width: 1080px) {
    .app-nav { display: none; }
    .app-user { display: none; }
    .nav-toggle { display: inline-flex; }
    .app-header nav { gap: 12px; }
}

@media (max-width: 640px) {
    body { font-size: 15px; }
    main { padding: 18px 14px calc(28px + var(--safe-bottom)); }
    .page-title { font-size: 1.2rem; }
    .page-head { margin-bottom: 16px; }
    .page-actions { width: 100%; }
    .page-actions .btn { flex: 1; }
    main > section, .card-body, .card-head { padding: 16px; }
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 14px; }
    .stat-value { font-size: 1.45rem; }
    .stat-label { font-size: 0.72rem; }
    .form-grid { grid-template-columns: 1fr; }
    /* iOS não dá zoom no foco quando a fonte tem 16px */
    input, select, textarea { font-size: 16px; }
    .pwa-banner { left: 12px; right: 12px; width: auto; }
}

/* --------------------------------------------------------------- Impressão -- */
@media print {
    .app-header, .mobile-nav, .page-actions, .pwa-banner, .btn { display: none !important; }
    body { background: #fff; }
    main { padding: 0; max-width: none; }
    .card, main > section { border: none; box-shadow: none; padding: 0; }
}
