/* ==========================================================================
   Design tokens — linguagem visual estilo iOS
   ========================================================================== */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --color-blue: #007AFF;
  --color-blue-dark: #0A84FF;
  --color-green: #34C759;
  --color-red: #FF3B30;
  --color-orange: #FF9500;
  --color-purple: #AF52DE;
  --color-yellow: #FFCC00;
  --color-teal: #30B0C7;

  --bg: #F2F2F7;
  --bg-elevated: #FFFFFF;
  --bg-grouped: #FFFFFF;
  --text-primary: #000000;
  --text-secondary: #6E6E73;
  --text-tertiary: #AEAEB2;
  --separator: rgba(60, 60, 67, 0.12);
  --sidebar-bg: rgba(246, 246, 248, 0.8);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-elevated: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1C1C1E;
    --bg-grouped: #1C1C1E;
    --text-primary: #FFFFFF;
    --text-secondary: #98989D;
    --text-tertiary: #636366;
    --separator: rgba(84, 84, 88, 0.6);
    --sidebar-bg: rgba(28, 28, 30, 0.8);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-elevated: 0 8px 30px rgba(0, 0, 0, 0.5);
    --color-blue: #0A84FF;
  }
}

:root[data-theme="light"] {
  --bg: #F2F2F7; --bg-elevated: #FFFFFF; --bg-grouped: #FFFFFF;
  --text-primary: #000000; --text-secondary: #6E6E73; --text-tertiary: #AEAEB2;
  --separator: rgba(60, 60, 67, 0.12); --sidebar-bg: rgba(246, 246, 248, 0.8);
}
:root[data-theme="dark"] {
  --bg: #000000; --bg-elevated: #1C1C1E; --bg-grouped: #1C1C1E;
  --text-primary: #FFFFFF; --text-secondary: #98989D; --text-tertiary: #636366;
  --separator: rgba(84, 84, 88, 0.6); --sidebar-bg: rgba(28, 28, 30, 0.8);
  --color-blue: #0A84FF;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--color-blue); color: #fff; }

button { font-family: var(--font); }

/* ==========================================================================
   Botões
   ========================================================================== */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--color-blue); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: rgba(120,120,128,0.12); color: var(--color-blue); }
.btn-block { width: 100%; }

/* ==========================================================================
   Inputs estilo iOS
   ========================================================================== */
.field {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  background: var(--bg-elevated);
  font-size: 16px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 4px rgba(0,122,255,0.15);
}
.field::placeholder { color: var(--text-tertiary); }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ==========================================================================
   App shell (sidebar + topbar)
   ========================================================================== */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--separator);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 20px;
  font-weight: 700;
  font-size: 17px;
}
.sidebar-brand .logo-dot {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--color-blue), var(--color-teal));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  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(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease;
}
.nav-item:hover { background: rgba(120,120,128,0.12); }
.nav-item.active { background: var(--color-blue); color: #fff; }
.nav-item .icon { font-size: 17px; width: 22px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
}
.sidebar-footer .nav-item { color: var(--color-red); }

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--separator);
  background: var(--sidebar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.topbar-title { font-size: 18px; font-weight: 700; flex-shrink: 0; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  min-width: 0;
  margin-left: 16px;
}
.user-chip span:not(.avatar) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar { flex-shrink: 0; }

@media (max-width: 640px) {
  .user-chip span:not(.avatar) { display: none; }
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-purple);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.kpi-card { display: flex; flex-direction: column; gap: 6px; }
.kpi-label { color: var(--text-secondary); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 28px; font-weight: 700; }
.kpi-trend { font-size: 13px; }
.kpi-trend.up { color: var(--color-green); }
.kpi-trend.down { color: var(--color-red); }

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 12px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.quick-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.quick-action:active { transform: scale(0.98); }
.quick-action .icon { font-size: 22px; }
.quick-action .label { font-weight: 600; font-size: 15px; }

/* ==========================================================================
   Toolbar
   ========================================================================== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.search-field { max-width: 340px; }
.toolbar .btn { flex-shrink: 0; margin-left: auto; }

/* ==========================================================================
   Listas estilo iOS
   ========================================================================== */
.list-card { padding: 0; overflow: hidden; }
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--separator);
  cursor: pointer;
  transition: background 0.1s ease;
}
.list-row > .chevron,
.list-row > span:last-child {
  flex-shrink: 0;
  margin-top: 2px;
  white-space: nowrap;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: rgba(120,120,128,0.08); }
.list-row-left { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 200px; }
.list-row-left > div { min-width: 0; }
.avatar-initials {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.list-row-name { font-weight: 600; font-size: 15px; }
.list-row-sub { font-size: 13px; color: var(--text-secondary); }
.chevron { color: var(--text-tertiary); font-size: 18px; flex-shrink: 0; }

.empty-state {
  display: none;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h2 { color: var(--text-primary); margin: 0 0 6px; font-size: 17px; }
.empty-state p { margin: 0; font-size: 14px; }

/* ==========================================================================
   Formulários
   ========================================================================== */
.form-grid { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
textarea.field { resize: vertical; font-family: var(--font); }
.btn-danger { background: var(--color-red); color: #fff; }

/* ==========================================================================
   Editor de registro (página cheia, ex: Cliente)
   ========================================================================== */
.editor-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.editor-title { font-size: 20px; font-weight: 700; flex: 1; min-width: 120px; }
.editor-header-actions { display: flex; gap: 10px; }

.segmented-tabs {
  display: flex;
  gap: 4px;
  background: rgba(120,120,128,0.12);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-btn {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab-btn.active { background: var(--bg-elevated); color: var(--text-primary); box-shadow: var(--shadow); }

.tab-panel { display: none; margin-bottom: 16px; }
.tab-panel.active { display: block; }

.segmented-control {
  display: inline-flex;
  background: rgba(120,120,128,0.12);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.segmented-option {
  appearance: none;
  border: none;
  background: transparent;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.segmented-option.active { background: var(--color-blue); color: #fff; }

.subsection { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--separator); }
.subsection-title { font-size: 14px; font-weight: 700; margin: 0 0 12px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  margin: 8px 0;
}
.checkbox-label input { width: 16px; height: 16px; }

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px 16px;
  margin-bottom: 8px;
}
.checkbox-grid .checkbox-label { margin: 4px 0; }

.input-with-action { display: flex; gap: 8px; }
.input-with-action .field { flex: 1; }
.btn-icon {
  flex-shrink: 0;
  width: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  background: var(--bg-elevated);
  cursor: pointer;
  font-size: 16px;
}
.btn-icon:hover { background: rgba(120,120,128,0.12); }

.btn-sm { padding: 8px 14px; font-size: 14px; }

.repeatable-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 10px;
  padding: 12px;
  background: rgba(120,120,128,0.06);
  border-radius: 10px;
  flex-wrap: wrap;
}
.repeatable-row .form-field { flex: 1; min-width: 140px; margin: 0; }
.repeatable-row .doc-status { flex-shrink: 0; align-self: center; min-width: 84px; text-align: center; }
.btn-remove-row {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,59,48,0.12);
  color: var(--color-red);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}
.btn-remove-row:hover { background: rgba(255,59,48,0.22); }

.doc-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.doc-badge.ok { background: rgba(52,199,89,0.15); color: var(--color-green); }
.doc-badge.warn { background: rgba(255,149,0,0.15); color: var(--color-orange); }
.doc-badge.expired { background: rgba(255,59,48,0.15); color: var(--color-red); }

.type-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  margin-right: 6px;
  vertical-align: middle;
}
.type-badge.pf { background: rgba(0,122,255,0.14); color: var(--color-blue); }
.type-badge.pj { background: rgba(175,82,222,0.16); color: var(--color-purple); }

/* ==========================================================================
   Orçamentos
   ========================================================================== */
.status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 6px;
  white-space: nowrap;
}
.status-badge.aberto { background: rgba(0,122,255,0.14); color: var(--color-blue); }
.status-badge.aprovado { background: rgba(52,199,89,0.15); color: var(--color-green); }
.status-badge.rejeitado { background: rgba(255,59,48,0.15); color: var(--color-red); }
.status-badge.expirado { background: rgba(142,142,147,0.18); color: var(--text-secondary); }
.status-badge.convertido { background: rgba(175,82,222,0.16); color: var(--color-purple); }
.status-badge.confirmada { background: rgba(0,122,255,0.14); color: var(--color-blue); }
.status-badge.andamento { background: rgba(255,149,0,0.15); color: var(--color-orange); }
.status-badge.concluida { background: rgba(52,199,89,0.15); color: var(--color-green); }
.status-badge.cancelada { background: rgba(255,59,48,0.15); color: var(--color-red); }

.orcamento-item-row .form-field { min-width: 120px; }
.orcamento-item-subtotal {
  flex-shrink: 0;
  align-self: center;
  min-width: 90px;
  text-align: right;
  font-weight: 600;
  font-size: 14px;
}

.orcamento-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--separator);
  font-size: 17px;
  font-weight: 700;
}

@media (max-width: 560px) {
  .form-row { grid-template-columns: 1fr; }
}

.placeholder-card {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.placeholder-card .icon { font-size: 40px; margin-bottom: 12px; }
.placeholder-card h2 { color: var(--text-primary); margin: 0 0 6px; }

.section { display: none; }
.section.active { display: block; }

/* ==========================================================================
   Modal (overlay + card centralizado)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.modal-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  padding: 24px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.modal-results-list { list-style: none; margin: 0; padding: 0; }
.modal-results-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

/* ==========================================================================
   Scrollbar discreta
   ========================================================================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(120,120,128,0.3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
