:root {
  --primary: #9c5b4a;
  --primary-strong: #8e4f40;
  --primary-soft: #f3dcd3;
  --primary-contrast: #ffffff;
  --bg: #f6ece8;
  --surface: #ffffff;
  --text: #3a2a26;
  --muted: #7f655e;
  --border: #ead6ce;
  --line: #f1e3dd;
  --danger: #b3261e;
  --ok: #2e7d32;
  --highlight: #f9d9c7;
  --dev: #ef6c00;
  --shadow: 0 4px 14px rgba(156, 91, 74, 0.10);
  --shadow-lift: 0 8px 22px rgba(156, 91, 74, 0.16);
  --font-display: "DM Serif Display", Georgia, "Times New Roman", serif;
  --font-body: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --banner-h: 0px;
  --header-h: 56px;
  --bar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --radius: 14px;
  --radius-card: 18px;
  --tap: 44px;
}

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

html { -webkit-text-size-adjust: 100%; accent-color: var(--primary); }

body {
  margin: 0;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(232, 196, 182, 0.55), transparent 60%),
    radial-gradient(90% 50% at 0% 100%, rgba(240, 214, 204, 0.6), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.is-dev { --banner-h: 28px; }

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: calc(var(--safe-top) + var(--banner-h));
}

a { color: inherit; }

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

::selection { background: var(--primary-soft); }

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

.loading, .empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

.empty { font-family: var(--font-display); font-size: 19px; }

/* DEV banner */
.dev-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: calc(var(--banner-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dev);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* Page */
.page { min-height: 100%; }

.page-with-tabs { padding-bottom: calc(var(--bar-h) + var(--safe-bottom) + 16px); }

.page-with-footer { padding-bottom: calc(var(--bar-h) + var(--safe-bottom) + 24px); }

.page-header {
  position: sticky;
  top: calc(var(--safe-top) + var(--banner-h));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--header-h);
  padding: 6px 12px;
  background: linear-gradient(to bottom, rgba(246, 236, 232, 0.94) 75%, rgba(246, 236, 232, 0));
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--text);
}

.page-heading {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0 4px;
}

.page-root .page-header { padding: 18px 16px 8px; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--primary);
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1.1;
}

.brand-sub {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}

.page-title {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 400;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-root .page-title { margin-top: 8px; font-size: 32px; }

.page-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 16px 16px;
}

.page-error {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 32px 16px;
  text-align: center;
}

/* Bottom tabs and fixed footer */
.tabs, .page-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 24px rgba(156, 91, 74, 0.10);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--bar-h);
  padding: 0 4px;
  color: #a68a82;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: color 0.2s ease;
}

.tab::before {
  content: '';
  width: 24px;
  height: 24px;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

.tab-active { color: var(--primary); font-weight: 600; }

.tab-contratos { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 3v5h5M9 13h6M9 17h4'/%3E%3C/svg%3E"); }
.tab-bases { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='3' width='16' height='6' rx='2'/%3E%3Crect x='4' y='11' width='16' height='4' rx='1.5'/%3E%3Crect x='4' y='17' width='16' height='4' rx='1.5'/%3E%3C/svg%3E"); }
.tab-clausulas { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6h16M4 10h16M4 14h10M4 18h7'/%3E%3C/svg%3E"); }
.tab-ajustes { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h10M18 7h2M4 17h4M12 17h8'/%3E%3Ccircle cx='16' cy='7' r='2'/%3E%3Ccircle cx='10' cy='17' r='2'/%3E%3C/svg%3E"); }

.page-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px calc(12px + var(--safe-bottom));
}

.page-footer > * { flex: 1; min-width: 0; }

.page-footer .btn { padding: 10px 12px; white-space: nowrap; }

.page-footer .btn-primary { flex: 1.5; }

/* Buttons */
[hidden] { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.btn:active:not(:disabled) { transform: scale(0.97); }

.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: 0 6px 16px rgba(156, 91, 74, 0.32);
}

.btn-primary:hover:not(:disabled) { background: var(--primary-strong); }

.btn-danger {
  background: var(--surface);
  border-color: rgba(179, 38, 30, 0.35);
  color: var(--danger);
  box-shadow: none;
}

.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--primary);
  font-size: 22px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.icon-btn:active:not(:disabled) { background: var(--primary-soft); }

.page-header .icon-btn { background: var(--surface); box-shadow: var(--shadow); font-size: 20px; }

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  padding-left: 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input::placeholder, textarea::placeholder { color: #b39c95; }

input::-webkit-calendar-picker-indicator { opacity: 0.5; cursor: pointer; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(156, 91, 74, 0.14);
}

input[type="search"] {
  padding-left: 42px;
  border-color: transparent;
  border-radius: 999px;
  box-shadow: var(--shadow);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a68a82' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M16 16l4 4'/%3E%3C/svg%3E") 15px center / 18px no-repeat;
}

input[type="search"]:focus { box-shadow: 0 0 0 4px rgba(156, 91, 74, 0.14), var(--shadow); }

/* Login */
.login {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 36px;
  min-height: calc(100dvh - var(--banner-h) - var(--safe-top));
  padding: 24px 20px calc(24px + var(--safe-bottom));
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  animation: rise 0.7s ease both;
}

.login-title {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 400;
  line-height: 1;
  color: var(--primary);
}

.login-sub {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--muted);
}

.login-tag {
  margin-top: 14px;
  font-family: var(--font-display);
  font-size: 19px;
  font-style: italic;
  color: var(--text);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 20px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-lift);
  animation: rise 0.7s 0.12s ease both;
}

.login-form .btn { margin-top: 4px; min-height: 52px; }

/* Toasts */
.toasts {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--bar-h) + var(--safe-bottom) + 12px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 600px;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  box-shadow: 0 8px 24px rgba(58, 42, 38, 0.3);
  pointer-events: auto;
  animation: rise 0.25s ease both;
}

.toast-error { background: var(--danger); }

/* Confirm dialog */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(58, 42, 38, 0.38);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade 0.2s ease both;
}

.dialog {
  width: 100%;
  max-width: 640px;
  padding: 24px 20px calc(18px + var(--safe-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  box-shadow: 0 -10px 30px rgba(58, 42, 38, 0.18);
  animation: sheet 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.dialog-text { margin-bottom: 20px; font-size: 17px; }

.dialog-actions {
  display: flex;
  gap: 8px;
}

.dialog-actions > * { flex: 1; }

@media (min-width: 641px) {
  .overlay { align-items: center; }
  .dialog { max-width: 420px; border-radius: 26px; }
}

/* Lists, cards, chips */
.list { display: flex; flex-direction: column; gap: 12px; }

.list > * { animation: rise 0.45s ease both; }
.list > :nth-child(2) { animation-delay: 0.04s; }
.list > :nth-child(3) { animation-delay: 0.08s; }
.list > :nth-child(4) { animation-delay: 0.12s; }
.list > :nth-child(5) { animation-delay: 0.16s; }
.list > :nth-child(6) { animation-delay: 0.2s; }
.list > :nth-child(n+7) { animation-delay: 0.24s; }

.row-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: var(--tap);
  padding: 14px 16px;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

a.row-card:active, button.row-card:active { transform: scale(0.985); box-shadow: var(--shadow-lift); }

.row-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.3;
}

.row-sub { font-size: 14px; color: var(--muted); }

.clause-preview {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-btn {
  min-height: var(--tap);
  padding: 4px 16px;
  border: 1px solid transparent;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.chip-btn:active { transform: scale(0.96); }

.clause-text { min-height: 180px; resize: none; overflow: hidden; line-height: 1.6; }

.section { display: flex; flex-direction: column; gap: 10px; }

.section-title {
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 400;
}

.dialog-form { display: flex; flex-direction: column; gap: 12px; }
.dialog-form .dialog-text { margin-bottom: 0; }

/* Picker (bottom sheet) */
.overlay-sheet { align-items: stretch; }

.picker {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  height: 100%;
  margin: 0 auto;
  padding-top: calc(var(--safe-top) + var(--banner-h));
  background: var(--bg);
  animation: sheet 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 4px 20px;
}

.picker-title { font-family: var(--font-display); font-size: 24px; font-weight: 400; }

.picker-tools { display: flex; flex-direction: column; gap: 8px; padding: 8px 16px 12px; }

.picker-list { flex: 1; overflow-y: auto; padding: 0 16px calc(16px + var(--safe-bottom)); }

.picker-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  min-height: var(--tap);
  margin-bottom: 8px;
  padding: 13px 16px;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.picker-item:active:not(:disabled) { transform: scale(0.985); }

.picker-item:disabled { opacity: 0.45; cursor: default; }

.picker-item-label { font-weight: 600; }
.picker-item-sub { font-size: 14px; color: var(--muted); }

@media (min-width: 641px) {
  .overlay-sheet { align-items: center; }
  .picker { height: 80vh; border-radius: 26px; padding-top: 0; }
}

/* Bases */
.base-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 8px 10px 16px;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.base-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }

.base-item-actions { display: flex; align-items: center; }

.base-item-actions .icon-btn { border-radius: 12px; font-size: 20px; }

.base-item-actions .icon-btn:disabled { opacity: 0.3; cursor: default; }

.warn-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius-card);
  background: #fbe9e7;
  color: var(--danger);
}

.dialog-scroll { max-height: calc(100dvh - var(--banner-h) - var(--safe-top) - 24px); overflow-y: auto; }

/* Wizard (novo contrato) */
.wz-progress { display: flex; flex-direction: column; gap: 8px; }

.wz-progress-text {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--primary);
}

.wz-progress-track { height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }

.wz-progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #c08371, var(--primary));
  transition: width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.wz-step { display: flex; flex-direction: column; gap: 12px; animation: rise 0.35s ease both; }

.wz-label {
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.15;
}

.wz-hint { color: var(--muted); }

.wz-input { min-height: 60px; padding: 14px 18px; border-radius: 18px; font-size: 21px; box-shadow: var(--shadow); border-color: transparent; }

.wz-snippet {
  padding: 14px 16px;
  border-radius: var(--radius-card);
  background: rgba(255, 255, 255, 0.6);
  color: #5c4842;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-line;
}

.wz-current {
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--highlight);
  color: var(--text);
  font-weight: 700;
}

.wz-empty { color: var(--muted); }
.wz-filled { font-weight: 600; }

.wz-contract {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 18px;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
  line-height: 1.65;
}

.wz-clause { white-space: pre-line; }
.wz-clause-title { font-weight: 700; }
.wz-field { font-weight: 600; color: var(--primary-strong); }
.wz-tap { border-bottom: 1px dashed var(--primary); cursor: pointer; }
.wz-missing { padding: 0 4px; border-radius: 6px; background: var(--highlight); }

/* Contratos (lista e contrato pronto) */
.page-with-fab { padding-bottom: calc(var(--bar-h) * 2 + var(--safe-bottom) + 24px); }

.page-fab {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bar-h) + var(--safe-bottom));
  z-index: 19;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 14px;
  background: linear-gradient(to top, rgba(246, 236, 232, 0.96) 60%, rgba(246, 236, 232, 0));
}

.btn-big { min-height: 54px; font-size: 17px; }

.legacy { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }

.legacy-summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 8px 4px;
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.legacy-summary::-webkit-details-marker { display: none; }
.legacy-summary::before { content: '▸'; width: 22px; font-family: var(--font-body); font-size: 14px; }
.legacy[open] > .legacy-summary::before { content: '▾'; }
.legacy[open] > .legacy-summary { margin-bottom: 10px; }

.contract-head { display: flex; flex-direction: column; gap: 4px; padding: 0 4px; }

.contract-title {
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 400;
  line-height: 1.2;
}

.menu { display: flex; flex-direction: column; gap: 12px; }

.menu-title {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 400;
  line-height: 1.25;
}

.menu-items { display: flex; flex-direction: column; }

.menu-item {
  min-height: 52px;
  padding: 12px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.menu-item:last-child { border-bottom: 0; }

.menu-item-danger { color: var(--danger); }

/* Motion */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheet {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
