/* Metro TBM — Mobile-first CSS */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-primary:    #1a56db;
  --c-primary-d:  #1342a5;
  --c-success:    #057a55;
  --c-danger:     #c81e1e;
  --c-warn:       #b45309;
  --c-bg:         #f5f7fa;
  --c-surface:    #ffffff;
  --c-border:     #d1d5db;
  --c-text:       #111827;
  --c-text-muted: #6b7280;
  --c-sidebar:    #1e2640;
  --c-sidebar-txt:#c9d1e0;
  --radius:       6px;
  --shadow:       0 1px 4px rgba(0,0,0,.08);
}

body { font-family: system-ui, -apple-system, sans-serif; background: var(--c-bg); color: var(--c-text); font-size: 14px; line-height: 1.5; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: -260px; width: 260px; height: 100vh;
  background: var(--c-sidebar); color: var(--c-sidebar-txt);
  display: flex; flex-direction: column;
  transition: left .25s ease; z-index: 100; overflow-y: auto;
}
.sidebar.open { left: 0; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 99; }
.sidebar-overlay.show { display: block; }

.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo { font-size: 18px; font-weight: 700; color: #fff; }
.sidebar-logo-img { max-width: 110px; max-height: 50px; object-fit: contain; display: block; }
.sidebar-close { background: none; border: none; color: var(--c-sidebar-txt); font-size: 18px; cursor: pointer; }

.sidebar-user { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.user-name { display: block; font-weight: 600; color: #fff; font-size: 13px; }
.user-role { margin-top: 4px; }
.sidebar-projeto { padding: 10px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.projeto-label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: rgba(255,255,255,.45); margin-bottom: 4px; }
.projeto-select { width: 100%; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); color: #fff; font-size: 13px; padding: 5px 8px; border-radius: var(--radius); cursor: pointer; }
.projeto-select:focus { outline: none; border-color: rgba(255,255,255,.4); }
.projeto-nome { display: block; font-size: 13px; font-weight: 600; color: #fff; }

.nav-list { list-style: none; flex: 1; padding: 8px 0; }
.nav-group { padding: 4px 0; }
.nav-group-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 6px 16px; background-color: transparent; -webkit-appearance: none; appearance: none; border: none; cursor: pointer; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #8b97b4; font-family: inherit; }
.nav-group-toggle:hover { color: #c9d1e0; }
.nav-group-arrow { font-size: 16px; transition: transform .2s ease; display: inline-block; }
.nav-group-toggle[aria-expanded="true"] .nav-group-arrow { transform: rotate(90deg); }
.nav-group-items { list-style: none; max-height: 0; overflow: hidden; transition: max-height .25s ease; }
.nav-group-items.open { max-height: 500px; }
.nav-link { display: block; padding: 7px 16px 7px 24px; color: var(--c-sidebar-txt); font-size: 13px; transition: background .15s; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.small { font-size: 12px; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; gap: 12px; }
.btn-logout { background: none; border: 1px solid rgba(255,255,255,.2); color: var(--c-sidebar-txt); padding: 5px 12px; border-radius: var(--radius); cursor: pointer; font-size: 12px; }
.btn-logout:hover { background: rgba(255,255,255,.1); }

/* ── Layout ────────────────────────────────────────────────────────────── */
.main-wrap { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--c-surface); border-bottom: 1px solid var(--c-border); box-shadow: var(--shadow); }
.menu-toggle { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--c-text); padding: 4px; }
.page-title { flex: 1; font-size: 16px; font-weight: 600; }
.content { padding: 16px; max-width: 1200px; margin: 0 auto; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius); border: none; cursor: pointer; font-size: 13px; font-weight: 500; text-decoration: none; transition: opacity .15s; }
.btn:hover { opacity: .88; text-decoration: none; }
.btn-primary  { background: var(--c-primary);  color: #fff; }
.btn-success  { background: var(--c-success);  color: #fff; }
.btn-danger   { background: var(--c-danger);   color: #fff; }
.btn-secondary{ background: #e5e7eb; color: var(--c-text); }
.btn-ghost    { background: transparent; color: var(--c-text-muted); border: 1px solid var(--c-border); }
.btn-sm       { padding: 4px 10px; font-size: 12px; }
.btn-full     { width: 100%; justify-content: center; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-card { max-width: 900px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-weight: 500; font-size: 13px; }
.form-group input, .form-group select, .form-group textarea {
  padding: 8px 10px; border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: 14px; background: #fff; width: 100%;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: 2px solid var(--c-primary); border-color: var(--c-primary);
}
.form-group .readonly { background: #f3f4f6; color: var(--c-text-muted); }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* ── Filters ───────────────────────────────────────────────────────────── */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.filter-input { padding: 7px 10px; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 13px; }
.filter-select { padding: 7px 10px; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 13px; background: #fff; }
.date-range-label { font-size: 12px; color: var(--c-text-muted); white-space: nowrap; }
.filter-bar-wrap .filter-input { flex: 1; min-width: 140px; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--c-primary, #1a56db); }
.col-filter {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 2px 4px;
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: #fff;
  color: var(--c-text, #111827);
  cursor: pointer;
  max-width: 160px;
}
.col-filter:focus { outline: 1px solid var(--c-primary, #1a56db); }
.col-filter option[value=""][selected] { color: #9ca3af; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--c-border); }
.table th { background: #f9fafb; font-weight: 600; color: var(--c-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:hover { background: #f9fafb; }
.table-sm td, .table-sm th { padding: 6px 8px; }
.actions { display: flex; gap: 4px; flex-wrap: wrap; }
.inline-form { display: inline; }
.empty { color: var(--c-text-muted); text-align: center; padding: 24px !important; }
.count-info { font-size: 12px; color: var(--c-text-muted); margin-top: 8px; }
.nowrap { white-space: nowrap; }
.mono { font-family: monospace; font-size: 12px; }
.small { font-size: 11px; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge-lg { padding: 4px 12px; font-size: 13px; }

/* Status badges */
.badge-status-pendente   { background: #fef3c7; color: #92400e; }
.badge-status-aprovado   { background: #d1fae5; color: #065f46; }
.badge-status-rejeitado  { background: #fee2e2; color: #991b1b; }
.badge-status-rascunho   { background: #f3f4f6; color: #374151; }

/* Role badges */
.badge-admin   { background: #ede9fe; color: #5b21b6; }
.badge-manager { background: #dbeafe; color: #1e40af; }
.badge-editor  { background: #d1fae5; color: #065f46; }
.badge-viewer  { background: #f3f4f6; color: #374151; }
.badge-powerbi { background: #fce7f3; color: #9d174d; }
.badge-active  { background: #d1fae5; color: #065f46; }
.badge-inactive{ background: #fee2e2; color: #991b1b; }
.badge-action  { background: #e0e7ff; color: #3730a3; font-family: monospace; border-radius: 4px; }

/* ── Flash messages ────────────────────────────────────────────────────── */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.flash-success { background: #d1fae5; color: #065f46; border-left: 4px solid var(--c-success); }
.flash-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--c-danger); }
.flash-info    { background: #dbeafe; color: #1e40af; border-left: 4px solid var(--c-primary); }

/* ── Dashboard ─────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat-card-warn { background: #fffbeb; border-color: #fde68a; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--c-primary); }
.stat-card-warn .stat-value { color: var(--c-warn); }
.stat-label { font-size: 12px; color: var(--c-text-muted); margin-top: 4px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.link-more { display: inline-block; margin-top: 10px; font-size: 13px; }

/* ── Detail page ───────────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.detail-list dt { font-weight: 600; color: var(--c-text-muted); font-size: 12px; }
.detail-list dd { font-size: 13px; }
.page-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.id-tag { font-size: 12px; font-family: monospace; color: var(--c-text-muted); font-weight: 400; }

/* ── Approval bar ──────────────────────────────────────────────────────── */
.approval-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius); margin-bottom: 16px; flex-wrap: wrap; }
.inline-reject-form { display: flex; gap: 8px; align-items: center; flex: 1; }
.reject-input { flex: 1; padding: 6px 10px; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 13px; }
.rejection-notice { background: #fee2e2; border-left: 4px solid var(--c-danger); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }

/* ── Attachments ───────────────────────────────────────────────────────── */
.attachment-list { list-style: none; margin-bottom: 12px; }
.attachment-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--c-border); }
.att-size { font-size: 11px; color: var(--c-text-muted); }
.upload-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* ── Login page ────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--c-sidebar); }
.login-card { background: var(--c-surface); border-radius: 10px; padding: 32px; width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,.18); }
.login-title { font-size: 24px; font-weight: 800; color: var(--c-primary); text-align: center; margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--c-text-muted); font-size: 13px; margin-bottom: 24px; }
.login-logo { display: block; max-width: 180px; max-height: 120px; object-fit: contain; margin: 0 auto 12px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }

/* ── Misc ──────────────────────────────────────────────────────────────── */
.row-inactive { opacity: .55; }
.json-block { background: #f3f4f6; border: 1px solid var(--c-border); border-radius: var(--radius); padding: 12px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; margin-top: 8px; }

/* ── Dashboard ─────────────────────────────────────────────────────────── */
.db-wrap { max-width: 1400px; }

.db-filters {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.db-filter-group { display: flex; flex-direction: column; gap: 4px; }
.db-filter-group label { font-size: 11px; font-weight: 600; color: var(--c-text-muted); text-transform: uppercase; }
.db-filter-group select,
.db-filter-group input { font-size: 13px; padding: 5px 8px; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-bg); color: var(--c-text); }

.db-section-label {
  font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--c-primary); border-bottom: 2px solid var(--c-primary);
  padding-bottom: 4px; margin: 20px 0 10px;
}

.db-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.db-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}

/* TBM info */
.db-tbm-info { min-width: 160px; }
.db-tbm-name { font-size: 22px; font-weight: 800; color: var(--c-primary); }
.db-tbm-sub  { font-size: 10px; font-weight: 600; color: var(--c-text-muted); text-transform: uppercase; margin: 2px 0; }
.db-tbm-anel { font-size: 28px; font-weight: 800; }
.db-kv-pair  { margin-top: 8px; }
.db-kv-label { font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--c-text-muted); display: block; }
.db-kv-val   { font-size: 16px; font-weight: 700; }

/* Horas cards */
.db-horas-card      { flex: 1; min-width: 220px; }
.db-horas-prod-card { flex: 1.5; min-width: 260px; }
.db-horas-formula   { display: flex; gap: 24px; flex-wrap: wrap; }
.db-horas-block     { min-width: 120px; }
.db-horas-label     { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--c-text-muted); margin-bottom: 4px; }
.db-horas-val       { font-size: 20px; font-weight: 800; color: var(--c-primary); }
.db-horas-val-lg    { font-size: 24px; }
.db-horas-val-xl    { font-size: 32px; }
.db-horas-sub-row   { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 12px; }

/* Gauge */
.db-gauge-card    { display: flex; flex-direction: column; align-items: center; min-width: 200px; max-width: 240px; }
.db-gauge-title   { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--c-text-muted); text-align: center; margin-bottom: 4px; }
.db-gauge-pct     { font-size: 22px; font-weight: 800; margin-top: -16px; }
.db-gauge-scale   { display: flex; justify-content: space-between; width: 100%; font-size: 9px; color: var(--c-text-muted); margin-top: 2px; }

/* Charts row */
.db-charts-row     { gap: 12px; }
.db-chart-card     { flex: 1; min-width: 280px; }
.db-charts-3col .db-chart-card { flex: 1; min-width: 240px; }
.db-card-title     { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--c-text-muted); margin-bottom: 8px; }
.db-legend         { font-size: 10px; color: var(--c-text-muted); display: flex; align-items: center; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; }
.db-legend-dot     { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* Manut KPIs */
.db-manut-top  { align-items: stretch; }
.db-manut-kpi  { display: flex; gap: 24px; flex-wrap: wrap; flex: 2; min-width: 280px; }
.db-manut-horas { flex: 1.5; min-width: 200px; display: flex; flex-direction: column; justify-content: center; }
.db-kv-lg      { min-width: 140px; }
.db-kv-label-sm { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--c-text-muted); margin-bottom: 4px; }
.db-kv-val-lg  { font-size: 24px; font-weight: 800; color: var(--c-primary); }

/* Subsistema filter inline */
.db-filter-inline { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 11px; font-weight: 600; color: var(--c-text-muted); }
.db-filter-inline select { font-size: 11px; padding: 3px 6px; border: 1px solid var(--c-border); border-radius: var(--radius); }

.db-footer { text-align: right; font-size: 10px; color: var(--c-text-muted); margin-top: 16px; padding-bottom: 12px; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .sidebar { left: 0; }
  .sidebar-close { display: none; }
  .sidebar-overlay { display: none !important; }
  .main-wrap { margin-left: 260px; }
  .menu-toggle { display: none; }
}
@media (max-width: 767px) {
  .form-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
