/* ============================================================
   Nowtia — Design System v0.1
   Sem frameworks externos. Variáveis CSS → tema configurável.
   ============================================================ */

/* ── Variáveis ──────────────────────────────────────────────── */
:root {
  --color-brand:       #2563EB;   /* azul primário */
  --color-brand-dark:  #1D4ED8;
  --color-brand-light: #EFF6FF;
  --color-accent:      #0EA5E9;

  --color-success:     #16A34A;
  --color-warning:     #D97706;
  --color-danger:      #DC2626;
  --color-info:        #0891B2;

  --color-text:        #111827;   /* títulos */
  --color-text-muted:  #6B7280;
  --color-text-light:  #9CA3AF;

  --color-bg:          #F9FAFB;
  --color-surface:     #FFFFFF;
  --color-border:      #E5E7EB;
  --color-border-soft: #F3F4F6;

  --sidebar-width:     240px;
  --sidebar-collapsed: 56px;
  --header-height:     52px;

  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-lg:   10px;

  --shadow-sm:   0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 2px 8px rgba(0,0,0,.08);
  --shadow-lg:   0 4px 16px rgba(0,0,0,.10);

  --font-sans:   'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
  --font-size:   14px;
  --line-height: 1.5;

  --transition: 150ms ease;
}

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

html { font-size: var(--font-size); scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  line-height: var(--line-height);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--color-brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1,h2,h3,h4,h5,h6 { color: var(--color-text); font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

/* ── Layout Shell ───────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--color-text);    /* dark sidebar */
  color: #E5E7EB;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition);
  overflow: hidden;
  position: sticky;
  top: 0;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-logo {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 28px; height: 28px;
  background: var(--color-brand);
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
  white-space: nowrap;
  opacity: 1;
  transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-logo-text { opacity: 0; pointer-events: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }

.nav-section {
  padding: 16px 12px 4px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition);
}

.sidebar.collapsed .nav-section { opacity: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 1px 8px;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,.70);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }

.nav-item.active {
  background: var(--color-brand);
  color: #fff;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-item-label {
  font-size: .875rem;
  opacity: 1;
  transition: opacity var(--transition);
}

.sidebar.collapsed .nav-item-label { opacity: 0; pointer-events: none; }

.nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
  transition: opacity var(--transition);
}

.sidebar.collapsed .nav-badge { opacity: 0; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 8px;
}

/* ── Botão recolher sidebar ──────────────────────────────────── */
.btn-toggle-sidebar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  border: none;
  background: rgba(255,255,255,.06);
  border-radius: var(--radius-md);
  color: rgba(255,255,255,.60);
  cursor: pointer;
  font-size: .8rem;
  transition: background var(--transition);
}

.btn-toggle-sidebar:hover { background: rgba(255,255,255,.12); color: #fff; }
.btn-toggle-sidebar svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar.collapsed .btn-toggle-sidebar-label { display: none; }

/* ── Main area ──────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8125rem;
  color: var(--color-text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.breadcrumb a {
  color: var(--color-text-muted);
  white-space: nowrap;
}

.breadcrumb a:hover { color: var(--color-brand); }

.breadcrumb-sep { color: var(--color-border); }

.breadcrumb-current {
  color: var(--color-text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text);
  font-size: .8125rem;
  transition: background var(--transition);
}

.topbar-user:hover { background: var(--color-bg); }

.avatar {
  width: 30px; height: 30px;
  background: var(--color-brand);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Page content ───────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 8px;
}

.card-title {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-text);
}

/* ── Grid ────────────────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1023px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 767px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
}

/* ── Stat tiles ──────────────────────────────────────────────── */
.stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-tile-label {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.stat-tile-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

.stat-tile-sub {
  font-size: .75rem;
  color: var(--color-text-muted);
}

.stat-tile.empty .stat-tile-value { color: var(--color-text-light); }

/* ── Tabelas ─────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

table { width: 100%; border-collapse: collapse; font-size: .875rem; }

thead th {
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border-soft);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: var(--color-bg); }

/* ── Formulários ─────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }

label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--color-text);
}

.form-control {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: .875rem;
  color: var(--color-text);
  background: var(--color-surface);
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font-sans);
}

.form-control:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-control::placeholder { color: var(--color-text-light); }

select.form-control { cursor: pointer; }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint { font-size: .75rem; color: var(--color-text-muted); }
.form-error { font-size: .75rem; color: var(--color-danger); font-weight: 500; }

/* ── Botões ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: .875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary   { background: var(--color-brand);   color: #fff; border-color: var(--color-brand); }
.btn-primary:hover   { background: var(--color-brand-dark); border-color: var(--color-brand-dark); }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }

.btn-danger    { background: var(--color-danger);  color: #fff; border-color: var(--color-danger); }
.btn-danger:hover    { background: #b91c1c; }

.btn-ghost  { background: transparent; color: var(--color-text-muted); border-color: transparent; }
.btn-ghost:hover  { background: var(--color-bg); color: var(--color-text); }

.btn-sm { padding: 4px 10px; font-size: .8125rem; }
.btn-lg { padding: 10px 20px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Badges de status ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}

.badge-blue    { background: #DBEAFE; color: #1E40AF; }
.badge-green   { background: #DCFCE7; color: #15803D; }
.badge-yellow  { background: #FEF9C3; color: #A16207; }
.badge-red     { background: #FEE2E2; color: #B91C1C; }
.badge-gray    { background: #F3F4F6; color: #4B5563; }
.badge-orange  { background: #FFEDD5; color: #C2410C; }
.badge-purple  { background: #F3E8FF; color: #7E22CE; }

/* ── Progress bar ────────────────────────────────────────────── */
.progress-wrap {
  background: var(--color-border);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--color-brand);
  transition: width .4s ease;
}

/* ── Alertas ─────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: .875rem;
  margin-bottom: 16px;
}

.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: #DCFCE7; color: #15803D; }
.alert-danger  { background: #FEE2E2; color: #B91C1C; }
.alert-warning { background: #FEF9C3; color: #A16207; }
.alert-info    { background: #E0F2FE; color: #0369A1; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-muted);
}

.empty-state svg { width: 48px; height: 48px; opacity: .3; }
.empty-state-title { font-weight: 600; color: var(--color-text); }
.empty-state-desc  { font-size: .875rem; max-width: 320px; }

/* ── Dropdown ────────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: none;
  overflow: hidden;
}

.dropdown-menu.open { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: .875rem;
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition);
}

.dropdown-item:hover { background: var(--color-bg); }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-divider { border-top: 1px solid var(--color-border); margin: 4px 0; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title { font-size: 1rem; font-weight: 600; }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
}

/* ── Login ───────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--color-bg);
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo-icon {
  width: 36px; height: 36px;
  background: var(--color-brand);
  border-radius: var(--radius-md);
  display: grid; place-items: center;
}

.login-logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -.5px;
}

/* ── Utilities ────────────────────────────────────────────────── */
.text-muted   { color: var(--color-text-muted); }
.text-sm      { font-size: .8125rem; }
.text-xs      { font-size: .75rem; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.font-bold    { font-weight: 700; }
.font-medium  { font-weight: 500; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col     { display: flex; flex-direction: column; }
.gap-2        { gap: 8px; }
.gap-3        { gap: 12px; }
.gap-4        { gap: 16px; }
.mt-1         { margin-top: 4px; }
.mt-2         { margin-top: 8px; }
.mt-3         { margin-top: 12px; }
.mt-4         { margin-top: 16px; }
.mb-2         { margin-bottom: 8px; }
.mb-4         { margin-bottom: 16px; }
.w-full       { width: 100%; }
.hidden       { display: none; }

/* ── Responsivo ──────────────────────────────────────────────── */
@media (max-width: 1365px) {
  :root { --sidebar-width: 220px; }
}

@media (max-width: 1023px) {
  .sidebar { width: var(--sidebar-collapsed); }
  .sidebar .sidebar-logo-text,
  .sidebar .nav-item-label,
  .sidebar .nav-section,
  .sidebar .nav-badge,
  .sidebar .btn-toggle-sidebar-label { display: none; }
  .sidebar .btn-toggle-sidebar { justify-content: center; }
}

@media (max-width: 767px) {
  .topbar { padding: 0 12px; }
  .topbar-user-name { display: none; }
}

@media (max-width: 389px) {
  :root { --sidebar-collapsed: 48px; }
  .page-content { padding: 12px; }
}

/* ── Scrollbar global ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-light); }
