@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Fraunces:ital,wght@0,300;0,600;1,300&display=swap');

/* ─── Tokens ─────────────────────────────────────────── */
:root {
  --bg:           #ffffff;
  --surface:      #fafafa;
  --surface2:     #f4f4f4;
  --charcoal:     #1a1a1a;

  --border:       #e8e8e8;
  --border-light: #f0f0f0;
  --divider:      #e8e8e8;

  --orange:       #F47920;
  --orange-dim:   #c95f0a;
  --orange-light: #fff3eb;
  --orange-faint: #fff8f4;

  --text:         #1a1a1a;
  --text-dim:     #555555;
  --text-muted:   #999999;

  --red:          #d93025;
  --green:        #16a34a;
  --amber:        #f59e0b;

  --sidebar-w:    200px;
  --topbar-h:     54px;
  --statusbar-h:  28px;
}

/* ─── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ──────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--charcoal);
  background-image: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(244,121,32,0.18) 0%, transparent 65%);
}

.auth-box {
  width: 360px;
  background: var(--bg);
  border-top: 3px solid var(--orange);
  padding: 44px 40px 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.auth-logo {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 22px;
  color: var(--orange);
  margin-bottom: 4px;
}

.auth-sub {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.auth-box .field { margin-bottom: 12px; }

.auth-error {
  font-size: 11px;
  color: var(--red);
  min-height: 18px;
  margin-bottom: 12px;
}

/* ─── Topbar ──────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--charcoal);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  z-index: 100;
}

.topbar-brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 18px;
  color: var(--orange);
  flex: 1;
}

.topbar-brand span {
  font-size: 9px;
  font-family: 'DM Mono', monospace;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  display: block;
  margin-top: -4px;
}

.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ─── Buttons ─────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 11px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary:hover { background: var(--orange-dim); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-sm {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid #3a3a3a;
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #aaa;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-sm:hover { border-color: var(--orange); color: var(--orange); }
.btn-sm:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-sm.light { border-color: var(--border); color: var(--text-dim); }
.btn-sm.light:hover { border-color: var(--orange); color: var(--orange); }

.btn-sm.accent { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-sm.accent:hover { background: var(--orange-dim); border-color: var(--orange-dim); }

.btn-sm.danger { border-color: transparent; color: var(--red); }
.btn-sm.danger:hover { border-color: var(--red); }

.btn-sm.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-sm.success:hover { opacity: .85; }

/* ─── Fields ──────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }

.field label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-muted);
  font-weight: 400;
}

.field input,
.field select,
.field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: all 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(244,121,32,0.08);
}

.field textarea { resize: vertical; min-height: 60px; }

.field input[type="file"] { padding: 6px; }

.field-hint {
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row.triple { grid-template-columns: 1fr 1fr 1fr; }
.field-row.full { grid-template-columns: 1fr; }

.section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--orange);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

/* ─── App layout ──────────────────────────────────────── */
#app { display: none; }
#app.visible { display: flex; flex-direction: column; }

.app-body {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
}

/* ─── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  padding: 16px 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
  overflow-y: auto;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 18px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 11px;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}

.sidebar nav a .icon { font-size: 13px; width: 16px; text-align: center; }
.sidebar nav a:hover { color: var(--orange); background: var(--orange-faint); }
.sidebar nav a.active {
  border-left-color: var(--orange);
  color: var(--orange);
  background: var(--orange-faint);
  font-weight: 500;
}

/* ─── Content ─────────────────────────────────────────── */
.content {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  min-height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
}

.secao { display: none; }
.secao.ativa { display: block; }

.secao-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.secao-titulo {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--charcoal);
}

/* ─── Toolbar ─────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: all 0.15s;
}

.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(244,121,32,0.08);
}

/* ─── Tables ──────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }

thead th {
  background: var(--charcoal);
  color: #aaa;
  padding: 9px 12px;
  text-align: left;
  font-size: 9px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  white-space: nowrap;
}

thead th.num { text-align: right; }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  vertical-align: middle;
}

tbody td.num { text-align: right; }

tbody tr:hover td { background: var(--orange-faint); }

tr.total-row td {
  border-top: 2px solid var(--orange);
  background: var(--orange-light);
  color: var(--orange);
  font-weight: 500;
}

.item-name { color: var(--text); font-weight: 500; font-size: 12px; }
.item-sub { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

.valor-positivo { color: var(--green); font-weight: 500; }
.valor-negativo { color: var(--red); font-weight: 500; }

/* ─── Tags ────────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 2px 7px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}

.tag-em_andamento { background: rgba(245,158,11,0.12); color: #92400e; }
.tag-concluida { background: rgba(22,163,74,0.1); color: var(--green); }
.tag-cancelada { background: rgba(217,48,37,0.1); color: var(--red); }
.tag-categoria { background: var(--surface2); color: var(--text-muted); }

/* ─── Result cards (métricas) ────────────────────────── */
.result-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

.result-card {
  background: var(--bg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.result-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--orange);
  opacity: 0.25;
}

.result-card:first-child::before { opacity: 1; }

.rc-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.rc-value {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 22px;
  color: var(--charcoal);
}

.result-card:first-child .rc-value { color: var(--orange); }

/* ─── Modals ──────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.58);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--bg);
  border-top: 3px solid var(--orange);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}

.modal-box.wide { max-width: 680px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header span {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--orange);
  font-weight: 500;
}

.modal-header button {
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  transition: color 0.15s;
}

.modal-header button:hover { color: var(--text); }

.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ─── Anexos grid ─────────────────────────────────────── */
.anexos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.anexo-item {
  border: 1px solid var(--border);
  border-left: 3px solid var(--orange);
  background: var(--bg);
  padding: 8px;
  position: relative;
}

.anexo-item img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
}

.anexo-item .anexo-pdf {
  width: 100%;
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 24px;
  color: var(--red);
  cursor: pointer;
}

.anexo-item .anexo-nome {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 6px;
  word-break: break-all;
  line-height: 1.3;
}

.anexo-item .anexo-del {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 22px;
  height: 22px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.anexo-item .anexo-del:hover { background: var(--red); }

/* ─── Status bar ──────────────────────────────────────── */
.statusbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--statusbar-h);
  background: var(--charcoal);
  border-top: 2px solid var(--orange);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
  z-index: 100;
  font-size: 10px;
  color: #888;
}

.statusbar strong { color: var(--orange); }

/* ─── Empty states ───────────────────────────────────── */
.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
}

/* ─── Toast ──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--statusbar-h) + 12px);
  right: 20px;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  z-index: 999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toastIn 0.15s ease;
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ─── Print ──────────────────────────────────────────── */
@media print {
  .topbar, .sidebar, .statusbar, .btn-sm, .toolbar { display: none !important; }
  .content { padding: 0; }
}

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: #ccc; }

/* ─── Responsive ─────────────────────────────────────── */
@media (max-width: 1100px) {
  .result-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ─── Detalhe da obra (aba individual) ──────────────── */
.obra-det-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.obra-det-head .secao-titulo { margin: 0; }

.obra-det-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.item-link { cursor: pointer; }
.item-link:hover { color: var(--orange); }

/* ─── Charts ─────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 8px;
}

.chart-card {
  border: 1px solid var(--border);
  border-top: 3px solid var(--orange);
  background: var(--bg);
  padding: 18px 20px 14px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chart-card-wide { grid-column: 1 / -1; }

.chart-title {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.charts-empty {
  padding: 44px;
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
  border: 1px dashed var(--border);
  margin-bottom: 24px;
}

.charts-empty strong { color: var(--orange); font-weight: 500; }

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}
