/* ============================================================
   Fiscal de Obras — Design System
   Prefeitura Municipal de Ubatuba/SP
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ---- Tokens ------------------------------------------------ */
:root {
  /* Brand */
  --brand-50:  #eff6ff;
  --brand-100: #dbeafe;
  --brand-200: #bfdbfe;
  --brand-300: #93c5fd;
  --brand-400: #60a5fa;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --brand-800: #1e40af;
  --brand-900: #1e3a8a;

  /* Semantic aliases (backward compat) */
  --blue-900: #1e3a8a;
  --blue-800: #1e40af;
  --blue-700: #1d4ed8;
  --blue-600: #2563eb;
  --blue-500: #3b82f6;
  --blue-400: #60a5fa;
  --blue-300: #93c5fd;
  --blue-200: #bfdbfe;
  --blue-100: #dbeafe;

  /* Semaphore */
  --verde:         #059669;
  --verde-hover:   #047857;
  --verde-bg:      #d1fae5;
  --amarelo:       #d97706;
  --amarelo-hover: #b45309;
  --amarelo-bg:    #fef3c7;
  --vermelho:      #dc2626;
  --vermelho-hover:#b91c1c;
  --vermelho-bg:   #fee2e2;

  /* Neutrals (Slate scale) */
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Semantic */
  --bg-body:       #eef2f7;
  --bg-primary:    #ffffff;
  --bg-secondary:  #f8fafc;
  --bg-sidebar:    #0f172a;
  --text-primary:  #0f172a;
  --text-secondary:#64748b;
  --text-muted:    #94a3b8;
  --border-color:  #e2e8f0;
  --shadow-color:  rgba(15,23,42,0.08);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 6px rgba(15,23,42,.05), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 15px rgba(15,23,42,.06), 0 4px 6px rgba(15,23,42,.04);
  --shadow-xl: 0 20px 40px rgba(15,23,42,.12);

  /* Layout */
  --sidebar-width: 260px;

  /* Spacing */
  --spacing-xs:  0.25rem;
  --spacing-sm:  0.5rem;
  --spacing-md:  1rem;
  --spacing-lg:  1.5rem;
  --spacing-xl:  2rem;
  --spacing-2xl: 3rem;

  /* Radius */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --radius-full: 9999px;

  /* Motion */
  --ease-fast: 120ms cubic-bezier(0.4,0,0.2,1);
  --ease-base: 200ms cubic-bezier(0.4,0,0.2,1);
  --ease-slow: 350ms cubic-bezier(0.4,0,0.2,1);

  /* Aliases for old templates */
  --transition-fast: var(--ease-fast);
  --transition-base: var(--ease-base);
  --transition-slow: var(--ease-slow);
  --header-height: 64px;
}

/* Dark mode */
[data-theme="dark"] {
  --bg-body:       #0b0f19;
  --bg-primary:    #131929;
  --bg-secondary:  #1a2236;
  --bg-sidebar:    #080d16;
  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --border-color:  #1e293b;
  --shadow-color:  rgba(0,0,0,.4);
}

/* ---- Reset ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.938rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-body);
}

/* ---- Scrollbar -------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ============================================================
   SIDEBAR
   ============================================================ */
.layout-wrapper { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, #0f172a 0%, #162032 100%);
  color: #fff;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 24px rgba(0,0,0,.18);
  transition: transform var(--ease-slow);
}

/* Brand / Logo */
.sidebar-header {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: #fff;
}

.sidebar-logo img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
}

.sidebar-brand-text { display: flex; flex-direction: column; }

.sidebar-brand-name {
  font-size: 0.938rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
}

.sidebar-brand-sub {
  font-size: 0.688rem;
  font-weight: 400;
  color: rgba(255,255,255,.45);
  letter-spacing: 0.03em;
  margin-top: 1px;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.625rem;
}

.nav-section-label {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 1rem 0.75rem 0.375rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--ease-fast), color var(--ease-fast);
  margin-bottom: 2px;
  position: relative;
}

.nav-item svg {
  flex-shrink: 0;
  opacity: .7;
  transition: opacity var(--ease-fast);
}

.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}

.nav-item:hover svg { opacity: 1; }

.nav-item.active {
  background: rgba(37,99,235,.25);
  color: #fff;
  font-weight: 600;
}

.nav-item.active svg { opacity: 1; }

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--brand-400);
  border-radius: 0 3px 3px 0;
}

/* Sidebar footer */
.sidebar-footer {
  flex-shrink: 0;
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.07);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.75rem;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.813rem;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  truncate: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: var(--spacing-xl);
  max-width: calc(100vw - var(--sidebar-width));
  min-height: 100vh;
}

/* Page Header */
.page-header {
  margin-bottom: 1.75rem;
}

.page-title {
  font-size: 1.625rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
  transition: box-shadow var(--ease-base), border-color var(--ease-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--gray-300);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ============================================================
   KPI STAT CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

.stat-card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--ease-base), transform var(--ease-base);
}

.stat-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--brand-500);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card.verde::before  { background: var(--verde); }
.stat-card.amarelo::before { background: var(--amarelo); }
.stat-card.vermelho::before { background: var(--vermelho); }

.stat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.875rem;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-50);
  color: var(--brand-600);
  flex-shrink: 0;
}

.stat-card.verde  .stat-icon { background: var(--verde-bg);    color: var(--verde); }
.stat-card.amarelo .stat-icon { background: var(--amarelo-bg); color: var(--amarelo); }
.stat-card.vermelho .stat-icon { background: var(--vermelho-bg); color: var(--vermelho); }

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.03em;
}

/* ============================================================
   BADGES / SEMÁFORO
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .7;
}

.badge.verde   { background: var(--verde-bg);   color: var(--verde); }
.badge.amarelo { background: var(--amarelo-bg); color: var(--amarelo); }
.badge.vermelho{ background: var(--vermelho-bg); color: var(--vermelho); }

/* ============================================================
   TABLES
   ============================================================ */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-primary);
}

thead { background: var(--gray-50); }

th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.688rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--text-primary);
  font-size: 0.875rem;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--ease-fast);
}

tbody tr:hover { background: var(--gray-50); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--ease-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--brand-600);
  color: #fff;
  border-color: var(--brand-600);
  box-shadow: 0 1px 2px rgba(37,99,235,.3), inset 0 1px 0 rgba(255,255,255,.1);
}

.btn-primary:hover {
  background: var(--brand-700);
  border-color: var(--brand-700);
  box-shadow: 0 4px 12px rgba(37,99,235,.35);
  transform: translateY(-1px);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border-color);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
  color: var(--text-primary);
}

.btn-success {
  background: var(--verde);
  color: #fff;
  border-color: var(--verde);
  box-shadow: 0 1px 2px rgba(5,150,105,.3);
}

.btn-success:hover {
  background: var(--verde-hover);
  border-color: var(--verde-hover);
  box-shadow: 0 4px 12px rgba(5,150,105,.3);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--vermelho);
  color: #fff;
  border-color: var(--vermelho);
}

.btn-danger:hover {
  background: var(--vermelho-hover);
  transform: translateY(-1px);
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: var(--spacing-lg); }

.form-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.813rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg-primary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: border-color var(--ease-fast), box-shadow var(--ease-fast);
  appearance: none;
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }

.form-input:hover,
.form-select:hover,
.form-textarea:hover { border-color: var(--gray-300); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-textarea { resize: vertical; min-height: 100px; line-height: 1.6; }

/* Custom select arrow */
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

/* ============================================================
   FILTERS
   ============================================================ */
.filters {
  display: flex;
  gap: var(--spacing-md);
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-item { flex: 1; min-width: 180px; }

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--spacing-lg);
}

.tab-list {
  display: flex;
  gap: 0;
  list-style: none;
  overflow-x: auto;
}

.tab-button {
  padding: 0.75rem 1.125rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--ease-fast), border-color var(--ease-fast);
  white-space: nowrap;
  margin-bottom: -1px;
}

.tab-button:hover { color: var(--text-primary); }

.tab-button.active {
  color: var(--brand-600);
  border-bottom-color: var(--brand-600);
  font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: var(--spacing-lg);
  border-top: 1px solid var(--border-color);
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-wrapper {
  display: flex;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1d4ed8 100%);
  position: relative;
  overflow: hidden;
}

.login-wrapper::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 80% at 20% 20%, rgba(37,99,235,.15) 0%, transparent 60%),
    radial-gradient(ellipse 60% 60% at 80% 80%, rgba(99,102,241,.1) 0%, transparent 60%);
}

.login-wrapper::after {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: rgba(255,255,255,.02);
  top: -200px; right: -200px;
}

.login-panel {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 2rem;
}

.login-card {
  background: rgba(255,255,255,.98);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0,0,0,.25), 0 0 0 1px rgba(255,255,255,.1);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin-bottom: 1rem;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.15));
}

.login-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-error {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #be123c;
}

.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
}

.btn-login {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.938rem;
  margin-top: 0.5rem;
}

.login-footer-text {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }

  .main-content {
    margin-left: 0;
    max-width: 100vw;
    padding: var(--spacing-md);
  }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: var(--spacing-md); }
  .page-title { font-size: 1.375rem; }
  .filters { flex-direction: column; }
  .filter-item { width: 100%; min-width: unset; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-center { text-align: center; }
.text-right  { text-align: right; }

.mt-1 { margin-top: var(--spacing-sm); }
.mt-2 { margin-top: var(--spacing-md); }
.mt-3 { margin-top: var(--spacing-lg); }
.mt-4 { margin-top: var(--spacing-xl); }

.mb-1 { margin-bottom: var(--spacing-sm); }
.mb-2 { margin-bottom: var(--spacing-md); }
.mb-3 { margin-bottom: var(--spacing-lg); }
.mb-4 { margin-bottom: var(--spacing-xl); }

.hidden { display: none !important; }

/* Divider */
.divider {
  height: 1px;
  background: var(--border-color);
  margin: var(--spacing-lg) 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--spacing-2xl);
  color: var(--text-secondary);
}

.empty-state svg {
  opacity: .3;
  margin-bottom: var(--spacing-md);
}
