/* SDM — Dashboard Apple-like com paleta SDM */

:root {
  --abyss: #0A1628;
  --deep-sea: #0F2138;
  --midnight: #091220;
  --gold: #C9A961;
  --gold-light: #E5C88A;
  --gold-deep: #8C6D2F;
  --pearl: #F4EFE6;
  --fog: #C9C3B8;
  --mist: #8A8578;
  --ink: #1A1A1A;
  --copper: #B86A3E;
  --seafoam: #4A7C7E;

  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface-2: #FAF8F3;
  --border: rgba(10, 22, 40, 0.08);
  --border-strong: rgba(10, 22, 40, 0.16);
  --text: var(--abyss);
  --text-muted: #5B6473;
  --text-faint: #8A8578;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-sm: 0 1px 2px rgba(10, 22, 40, 0.04), 0 1px 1px rgba(10, 22, 40, 0.03);
  --shadow: 0 4px 16px rgba(10, 22, 40, 0.06), 0 2px 4px rgba(10, 22, 40, 0.04);
  --shadow-lg: 0 12px 40px rgba(10, 22, 40, 0.10), 0 4px 12px rgba(10, 22, 40, 0.06);

  --ease: cubic-bezier(0.22, 0.9, 0.3, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* App shell */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  display: grid;
  place-items: center;
  color: var(--abyss);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.sidebar-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.sidebar-sub {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all 160ms var(--ease);
  cursor: pointer;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--abyss);
  color: var(--pearl);
}

.nav-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.main {
  padding: 40px 48px;
  max-width: 1280px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

.page-title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.page-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: all 240ms var(--ease);
}

.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.card-desc {
  color: var(--text-muted);
  font-size: 13px;
}

/* Form */
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  margin-bottom: 20px;
}

.form-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.form-section-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--abyss);
}

.form-section-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.form-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group.full {
  grid-column: 1 / -1;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}

.form-hint {
  font-size: 12px;
  color: var(--text-faint);
}

.form-input {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  transition: all 160ms var(--ease);
}

.form-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(201, 169, 97, 0.15);
}

.form-input[type="date"] {
  font-family: inherit;
}

/* Upload */
.upload {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  transition: all 200ms var(--ease);
  cursor: pointer;
  background: var(--surface-2);
}

.upload:hover {
  border-color: var(--gold);
  background: rgba(201, 169, 97, 0.04);
}

.upload.has-file {
  border-style: solid;
  border-color: var(--seafoam);
  background: rgba(74, 124, 126, 0.05);
}

.upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-deep));
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  color: var(--abyss);
  font-size: 18px;
}

.upload.has-file .upload-icon {
  background: linear-gradient(135deg, var(--seafoam), #2F5758);
  color: #fff;
}

.upload-title {
  font-weight: 600;
  font-size: 14px;
}

.upload-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.upload-filename {
  font-size: 12px;
  color: var(--seafoam);
  font-weight: 600;
  margin-top: 6px;
}

.sheets-or {
  margin: 10px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sheets-or::before,
.sheets-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.sheets-url-loaded {
  color: var(--seafoam);
  font-weight: 600;
  font-size: 12px;
  margin-top: 6px;
}

.sheets-url-error {
  color: #E74C3C;
  font-size: 12px;
  margin-top: 6px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: all 200ms var(--ease);
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--abyss);
  color: var(--pearl);
  border-color: var(--abyss);
}

.btn-primary:hover {
  background: var(--deep-sea);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--abyss);
  border-color: transparent;
  font-weight: 700;
}

.btn-gold:hover {
  filter: brightness(1.05);
}

.btn-lg {
  height: 52px;
  padding: 0 28px;
  font-size: 15px;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
}

/* Table-like history */
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.history-card-wrap {
  position: relative;
}
.history-card-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
  z-index: 2;
}
.history-card-wrap .history-card-delete,
.history-card-wrap .history-card-action {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.9;
  transition: background 160ms var(--ease), color 160ms var(--ease), border-color 160ms var(--ease), transform 160ms var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-decoration: none;
  font-family: inherit;
}
.history-card-wrap .history-card-delete { font-size: 18px; }
.history-card-wrap .history-card-delete:hover {
  background: #3a1414;
  color: #ff9b9b;
  border-color: #5a1e1e;
  transform: scale(1.08);
}
.history-card-wrap .history-card-action:hover {
  background: rgba(198, 156, 92, 0.16);
  color: var(--gold-deep);
  border-color: rgba(198, 156, 92, 0.45);
  transform: scale(1.08);
}
.history-card-wrap .history-card-wa:hover {
  background: rgba(37, 211, 102, 0.14);
  color: #1DA851;
  border-color: rgba(37, 211, 102, 0.5);
}
.history-card-wrap .history-card-action.copied {
  background: rgba(37, 211, 102, 0.18);
  color: #1DA851;
  border-color: rgba(37, 211, 102, 0.55);
}
.history-card-wrap .history-card-delete:disabled,
.history-card-wrap .history-card-action:disabled {
  cursor: wait;
  opacity: 0.6;
}

.history-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  transition: border-color 160ms var(--ease), transform 160ms var(--ease), box-shadow 200ms var(--ease);
}
.history-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 20px 40px -24px rgba(198, 156, 92, 0.35);
}
.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 4px;
  padding-right: 200px;
}
@media (max-width: 640px) {
  .history-card-header { padding-right: 0; padding-top: 44px; }
}
.history-card-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.history-card-date-row {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.history-card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  min-height: 18px;
}
.history-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.history-card-chip {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(198, 156, 92, 0.12);
  color: var(--gold-deep);
  border: 1px solid rgba(198, 156, 92, 0.25);
}
.history-card-chip-muted {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.history-card-chip-client {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(118, 156, 142, 0.14);
  color: var(--seafoam);
  border: 1px solid rgba(118, 156, 142, 0.3);
  letter-spacing: 0.02em;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 20px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  transition: background 160ms var(--ease);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover {
  background: var(--surface-2);
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.history-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.history-meta {
  font-size: 12px;
  color: var(--text-faint);
}

.history-empty {
  grid-column: 1 / -1;
  padding: 60px 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.history-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--pearl), var(--fog));
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  font-size: 24px;
}

/* Column mapper */
.mapper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.mapper-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mapper-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mapper-select {
  height: 38px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238A8578' d='M6 8.5L2 4.5h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: all 160ms var(--ease);
}

.mapper-select:hover {
  border-color: var(--gold);
}

.mapper-select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.15);
}

.mapper-select.empty {
  color: var(--text-faint);
  font-style: italic;
}

.mapper-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(138, 133, 120, 0.15);
  color: var(--mist);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Tabs (pesquisa) */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-bottom: 20px;
}

.tab {
  padding: 8px 16px;
  border-radius: 999px;
  border: none;
  background: transparent;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  cursor: pointer;
  transition: all 200ms var(--ease);
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--abyss);
  color: var(--gold-light);
  box-shadow: var(--shadow-sm);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Bar row dual (pesquisa comparativa) */
.bar-row {
  display: grid;
  grid-template-columns: 1fr 120px 120px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.bar-row:last-child {
  border-bottom: none;
}

.bar-row-value {
  font-weight: 500;
  color: var(--text);
}

.bar-track {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-bg {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 800ms var(--ease);
}

.bar-fill.comp {
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
}

.bar-fill.geral {
  background: linear-gradient(90deg, #2F5758, var(--seafoam));
}

.bar-pct {
  font-size: 12px;
  font-weight: 600;
  min-width: 48px;
  text-align: right;
  color: var(--text);
}

.bar-legend {
  display: flex;
  gap: 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.bar-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.bar-legend-dot.comp { background: var(--gold); }
.bar-legend-dot.geral { background: var(--seafoam); }

/* Progress steps */
.steps {
  display: flex;
  gap: 8px;
  margin-bottom: 32px;
}

.step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
}

.step.active {
  border-color: var(--gold);
  background: rgba(201, 169, 97, 0.06);
  color: var(--text);
}

.step.done {
  color: var(--seafoam);
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 11px;
}

.step.active .step-num {
  background: var(--gold);
  color: var(--abyss);
}

.step.done .step-num {
  background: var(--seafoam);
  color: #fff;
}

/* Toast/alert */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid;
}

.alert-info {
  background: rgba(74, 124, 126, 0.08);
  border-color: rgba(74, 124, 126, 0.2);
  color: var(--seafoam);
}

.alert-warn {
  background: rgba(184, 106, 62, 0.08);
  border-color: rgba(184, 106, 62, 0.25);
  color: var(--copper);
}

.alert-error {
  background: rgba(220, 53, 69, 0.06);
  border-color: rgba(220, 53, 69, 0.2);
  color: #B22A3A;
}

.alert-success {
  background: rgba(58, 118, 74, 0.08);
  border-color: rgba(58, 118, 74, 0.25);
  color: #3A764A;
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(201, 169, 97, 0.12), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(74, 124, 126, 0.10), transparent 40%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  display: grid;
  place-items: center;
  margin: 0 auto 20px;
  font-weight: 700;
  font-size: 20px;
  color: var(--abyss);
  box-shadow: var(--shadow);
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

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

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; overflow-x: auto; }
  .sidebar-brand { border-bottom: none; padding: 0; margin: 0 16px 0 0; }
  .main { padding: 24px 20px; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
}
