:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --ink: #171717;
  --muted: #70706c;
  --line: #deded9;
  --line-strong: #bdbdb7;
  --accent: #171717;
  --success: #24724b;
  --warning: #a15c00;
  --danger: #a52f2f;
  --info: #285f91;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 28px rgba(0,0,0,.07);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 264px 1fr; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: #fff; border-right: 1px solid var(--line); padding: 20px 16px;
  display: flex; flex-direction: column; z-index: 30;
}
.brand-block { padding: 8px 10px 24px; border-bottom: 1px solid var(--line); }
.brand-logo { width: 190px; max-width: 100%; height: auto; display: block; }
.brand-subtitle { display: block; margin-top: 8px; color: var(--muted); font-size: 13px; letter-spacing: .02em; }
.side-nav { display: grid; gap: 5px; padding: 22px 0; }
.side-nav a {
  text-decoration: none; display: flex; align-items: center; gap: 11px;
  min-height: 44px; padding: 10px 12px; border-radius: 11px; color: #444;
  font-weight: 650; font-size: 14px;
}
.side-nav a span { width: 22px; text-align: center; font-size: 18px; }
.side-nav a:hover { background: var(--surface-2); }
.side-nav a.active { color: #fff; background: var(--ink); }
.side-nav a.nav-emphasis:not(.active) { border: 1px solid var(--line-strong); color: var(--ink); }
.sidebar-footer {
  margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 14px 10px;
  background: var(--surface-2); border-radius: 12px; color: var(--muted);
}
.sidebar-footer strong, .sidebar-footer small { display: block; }
.sidebar-footer strong { color: var(--ink); font-size: 13px; }
.sidebar-footer small { font-size: 11px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warning); flex: 0 0 auto; }

.main-column { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; min-height: 86px; padding: 16px 28px;
  display: flex; align-items: center; gap: 16px; background: rgba(244,244,242,.94);
  backdrop-filter: blur(12px); border-bottom: 1px solid rgba(222,222,217,.85);
}
.topbar h1 { margin: 0; font-size: 25px; line-height: 1.15; letter-spacing: -.03em; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-button { border: 0; background: transparent; cursor: pointer; border-radius: 9px; padding: 8px; }
.menu-button { display: none; font-size: 22px; }
.content { padding: 26px 28px 60px; max-width: 1560px; margin: 0 auto; }

.button {
  border: 1px solid transparent; border-radius: 10px; min-height: 40px; padding: 9px 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  text-decoration: none; font-weight: 750; font-size: 13px; transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button-primary { background: var(--ink); color: #fff; }
.button-secondary { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.button-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.button-danger { background: #fff; color: var(--danger); border-color: #e6c6c6; }
.button-success { background: var(--success); color: #fff; }
.button-small { min-height: 34px; padding: 7px 10px; font-size: 12px; }
.button-block { width: 100%; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stack { display: grid; gap: 14px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.grow { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.card-elevated { box-shadow: var(--shadow); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 16px; }
.card-header h2, .card-header h3 { margin: 0; letter-spacing: -.02em; }
.card-header h2 { font-size: 18px; }
.card-header h3 { font-size: 15px; }
.card-header p { color: var(--muted); margin: 5px 0 0; font-size: 13px; }
.section-title { margin: 0 0 14px; font-size: 18px; letter-spacing: -.02em; }
.section-space { margin-top: 24px; }

.metric-card { min-height: 142px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-label { color: var(--muted); font-size: 13px; font-weight: 650; }
.metric-value { font-size: 31px; font-weight: 850; letter-spacing: -.04em; margin: 8px 0; }
.metric-foot { color: var(--muted); font-size: 12px; }
.metric-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); font-size: 18px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px;
  font-size: 11px; line-height: 1; font-weight: 800; background: #ececea; color: #4e4e4b; white-space: nowrap;
}
.badge-success { background: #e5f3eb; color: var(--success); }
.badge-warning { background: #f8eddc; color: var(--warning); }
.badge-danger { background: #f8e5e5; color: var(--danger); }
.badge-info { background: #e6eff7; color: var(--info); }
.badge-dark { background: var(--ink); color: #fff; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafaf8; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }

.field { display: grid; gap: 7px; }
.field label { font-weight: 750; font-size: 12px; color: #3f3f3c; }
.field small { color: var(--muted); font-size: 11px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 43px; padding: 10px 11px; border: 1px solid var(--line-strong);
  background: #fff; border-radius: 10px; color: var(--ink); outline: none;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23,23,23,.08); }
.field input:disabled, .field select:disabled { background: #efefed; color: #888; }
.field-error { color: var(--danger); font-size: 11px; font-weight: 700; }
.form-section { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.form-section h3 { margin: 0 0 13px; font-size: 14px; }

.segmented { display: grid; grid-template-columns: repeat(auto-fit,minmax(120px,1fr)); gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; min-height: 44px; align-items: center; justify-content: center; padding: 9px 10px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: #fff; cursor: pointer;
  text-align: center; font-size: 12px; font-weight: 750;
}
.segmented input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.segmented input:disabled + span { opacity: .45; cursor: not-allowed; background: #eee; }

.quantity-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(116px,1fr)); gap: 9px; }
.quantity-cell { background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 10px; }
.quantity-cell strong { display: block; font-size: 12px; margin-bottom: 7px; }
.quantity-control { display: grid; grid-template-columns: 32px 1fr 32px; align-items: center; gap: 4px; }
.quantity-control button { height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); cursor: pointer; font-weight: 850; }
.quantity-control input { min-width: 0; height: 32px; text-align: center; padding: 3px; border: 1px solid var(--line); border-radius: 8px; font-weight: 800; }

.quote-layout { display: grid; grid-template-columns: minmax(0,1.65fr) minmax(330px,.75fr); gap: 20px; align-items: start; }
.sticky-card { position: sticky; top: 108px; }
.item-card { border: 1px solid var(--line); border-radius: 14px; background: #fff; overflow: hidden; }
.item-card-head { padding: 14px 16px; background: var(--surface-2); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-bottom: 1px solid var(--line); }
.item-card-body { padding: 15px 16px; }
.item-card h4 { margin: 0; font-size: 14px; }
.item-card p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.price-breakdown { display: grid; gap: 8px; margin-top: 12px; }
.price-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.price-row.total { border-top: 1px dashed var(--line-strong); padding-top: 10px; font-size: 14px; font-weight: 850; }
.summary-total { font-size: 28px; font-weight: 900; letter-spacing: -.04em; }
.summary-line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 13px; }
.summary-line + .summary-line { border-top: 1px solid #eee; }
.summary-line strong { font-variant-numeric: tabular-nums; }

.empty-state { padding: 42px 24px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: rgba(255,255,255,.6); }
.empty-state .empty-icon { font-size: 34px; margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 6px; }
.empty-state p { margin: 0 auto 16px; color: var(--muted); max-width: 500px; font-size: 13px; }

.search-row { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.search-row input { flex: 1; min-height: 42px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 12px; }

.client-card { display: grid; gap: 12px; }
.client-card h3 { margin: 0; font-size: 16px; }
.client-meta { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 8px 15px; }
.client-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.client-stat { padding: 10px; background: var(--surface-2); border-radius: 10px; }
.client-stat small, .client-stat strong { display: block; }
.client-stat small { color: var(--muted); font-size: 10px; }
.client-stat strong { margin-top: 3px; font-size: 13px; }

.progress-list { display: grid; gap: 7px; }
.progress-step { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 9px; padding: 9px; border-radius: 10px; }
.progress-step.active { background: #f1f1ee; }
.progress-step.done .step-dot { background: var(--success); color: #fff; }
.step-dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: #e8e8e4; font-size: 11px; font-weight: 850; }
.progress-step strong { display: block; font-size: 12px; }
.progress-step small { color: var(--muted); font-size: 10px; }

.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 290px); gap: 13px; overflow-x: auto; padding-bottom: 12px; }
.kanban-column { background: #eaeae7; border-radius: 14px; padding: 11px; min-height: 330px; }
.kanban-column-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 3px 4px 11px; }
.kanban-column-head h3 { margin: 0; font-size: 13px; }
.kanban-card { background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 12px; margin-bottom: 9px; box-shadow: 0 3px 10px rgba(0,0,0,.04); }
.kanban-card h4 { margin: 0 0 4px; font-size: 13px; }
.kanban-card p { margin: 0; color: var(--muted); font-size: 11px; }
.kanban-actions { display: flex; gap: 5px; margin-top: 10px; }

.notice { padding: 13px 14px; border-radius: 11px; font-size: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.notice-warning { background: #fff7e9; border-color: #efd5a7; color: #754300; }
.notice-info { background: #edf5fb; border-color: #c9ddec; color: #244f73; }
.notice-success { background: #ecf7f0; border-color: #c5e1d0; color: #205f40; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 18px; }
.modal { width: min(720px,100%); max-height: calc(100vh - 36px); overflow-y: auto; background: #fff; border-radius: 18px; box-shadow: 0 25px 80px rgba(0,0,0,.22); }
.modal-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 17px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 20px; }
.modal-footer { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; background: #fff; border-top: 1px solid var(--line); }
.close-button { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 9px; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 200; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; background: var(--ink); color: #fff; border-radius: 999px; padding: 11px 17px; font-size: 12px; font-weight: 750; transition: .2s ease; box-shadow: var(--shadow); }
.toast.show { transform: translate(-50%,0); opacity: 1; }

.credit-positive { color: var(--success); font-weight: 800; }
.credit-negative { color: var(--danger); font-weight: 800; }

.print-only { display: none; }

@media (max-width: 1120px) {
  .grid-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .quote-layout { grid-template-columns: 1fr; }
  .sticky-card { position: static; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: min(288px,86vw); transition: transform .2s ease; box-shadow: 15px 0 50px rgba(0,0,0,.18); }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: inline-grid; }
  .topbar { padding: 13px 16px; min-height: 76px; }
  .topbar h1 { font-size: 21px; }
  .topbar-actions .button-ghost { display: none; }
  .content { padding: 18px 15px 50px; }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: 14px; }
  .topbar-actions .button-primary { font-size: 0; width: 40px; padding: 0; }
  .topbar-actions .button-primary::before { content: '+'; font-size: 22px; }
  .client-stats { grid-template-columns: 1fr 1fr; }
  .segmented { grid-template-columns: 1fr 1fr; }
  .quote-layout { gap: 14px; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 94vh; }
}

@media print {
  .sidebar, .topbar, .no-print, .toast, .modal-backdrop { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .print-only { display: block; }
}

/* ===== Autenticação e sincronização v0.2 ===== */
.hidden { display: none !important; }
.auth-shell {
  min-height: 100vh; padding: 28px; display: grid; place-items: center;
  background:
    radial-gradient(circle at 12% 12%, rgba(0,0,0,.055), transparent 28%),
    linear-gradient(145deg, #f7f7f5, #e9e9e5);
}
.auth-card {
  width: min(100%, 480px); background: #fff; border: 1px solid var(--line);
  border-radius: 22px; box-shadow: 0 28px 70px rgba(0,0,0,.12); padding: 30px;
}
.auth-logo { width: min(100%, 290px); height: auto; display: block; margin: 2px auto 25px; }
.auth-copy { text-align: center; margin-bottom: 22px; }
.auth-copy h1 { margin: 13px 0 7px; font-size: 27px; letter-spacing: -.04em; }
.auth-copy p { color: var(--muted); font-size: 13px; margin: 0 auto; max-width: 390px; }
.auth-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; margin: 19px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.auth-help { margin: 15px 0 0; color: var(--muted); font-size: 10px; text-align: center; line-height: 1.55; }
.auth-card .notice { margin-bottom: 14px; }
.sync-footer { cursor: pointer; transition: background .15s ease; }
.sync-footer:hover { background: #ecece8; }
.sync-footer .status-dot { background: var(--warning); box-shadow: 0 0 0 4px rgba(161,92,0,.10); }
.sync-footer[data-status="synced"] .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(36,114,75,.10); }
.sync-footer[data-status="saving"] .status-dot { background: var(--info); box-shadow: 0 0 0 4px rgba(40,95,145,.10); animation: pulse-sync 1s infinite; }
.sync-footer[data-status="offline"] .status-dot,
.sync-footer[data-status="error"] .status-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(165,47,47,.10); }
#signedUser { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
@keyframes pulse-sync { 50% { transform: scale(.7); opacity: .55; } }

@media (max-width: 760px) {
  .auth-shell { padding: 14px; align-items: start; padding-top: 7vh; }
  .auth-card { padding: 23px 19px; border-radius: 18px; }
  .auth-logo { width: 245px; }
  .topbar-actions #syncButton, .topbar-actions #backupButton, .topbar-actions #logoutButton { display: none; }
}
