@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2f3d;
  --text: #e8eaef;
  --text-muted: #8b92a5;
  --accent: #14b8a6;
  --accent-hover: #0d9488;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #22c55e;
  --radius: 12px;
  --sidebar-w: 260px;
}

html {
  font-size: 15px;
  overflow-x: hidden;
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

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

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(20,184,166,.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(20,184,166,.05) 0%, transparent 40%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  box-shadow: 0 24px 48px rgba(0,0,0,.4);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.login-logo p {
  color: var(--text-muted);
  font-size: .875rem;
  margin-top: 4px;
}

/* Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0 12px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-brand h2 {
  font-size: 1.125rem;
  font-weight: 700;
}

.sidebar-brand span {
  font-size: .75rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.sidebar-nav { flex: 1; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: .9rem;
  transition: all .15s;
  margin-bottom: 2px;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(20,184,166,.12);
  color: var(--accent);
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  padding: 8px 12px;
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.sidebar-user strong {
  display: block;
  color: var(--text);
  font-size: .875rem;
}

.main-content {
  flex: 1;
  min-width: 0;
  width: calc(100vw - var(--sidebar-w));
  max-width: calc(100vw - var(--sidebar-w));
  margin-left: var(--sidebar-w);
  padding: 24px 20px 40px;
  overflow-x: hidden;
}

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

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.page-header p {
  color: var(--text-muted);
  font-size: .875rem;
  margin-top: 4px;
}

/* Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

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

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 4px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  min-width: 0;
}

.card-form {
  width: 100%;
  min-width: 0;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.card-body {
  padding: 20px;
  min-width: 0;
  max-width: 100%;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  transition: border-color .15s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20,184,166,.15);
}

input::placeholder { color: var(--text-muted); opacity: .6; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  line-height: 1;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

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

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

.btn-danger {
  background: rgba(239,68,68,.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,.3);
}

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

.btn-sm { padding: 6px 12px; font-size: .8rem; }

.btn-block { width: 100%; }

/* Table */
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-radius: 0 0 var(--radius) var(--radius);
}

table,
.data-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: .8125rem;
}

thead th {
  text-align: left;
  padding: 8px 10px;
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  background: var(--surface);
}

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

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

/* Colunas compactas */
.data-table .col-check { width: 36px; }

.data-table .cell-compact {
  width: 1%;
  white-space: nowrap;
}

.data-table .col-actions {
  width: 130px;
  white-space: nowrap;
}

.data-table .cell-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0;
}

.data-table .cell-ellipsis strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.data-table .cell-mono {
  font-family: ui-monospace, monospace;
  font-size: .75rem;
}

.td-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: nowrap;
}

.td-actions .btn-sm {
  padding: 5px 8px;
  font-size: .72rem;
}

.text-muted { color: var(--text-muted); }
.text-mono { font-family: ui-monospace, monospace; font-size: .8rem; }
.text-right { text-align: right; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-admin { background: rgba(20,184,166,.15); color: var(--accent); }
.badge-agent { background: rgba(139,146,165,.15); color: var(--text-muted); }

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: .875rem;
  font-weight: 500;
}

.alert-success {
  background: rgba(34,197,94,.12);
  border: 1px solid rgba(34,197,94,.3);
  color: var(--success);
}

.alert-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: var(--danger);
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
  max-width: 220px;
}

.search-input { min-width: 200px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state p { margin-bottom: 16px; }

/* Bulk actions */
.col-check {
  text-align: center;
}

.col-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(20,184,166,.08);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

.bulk-count {
  font-size: .875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.bulk-count strong { color: var(--accent); }

.bulk-select {
  max-width: 220px;
  padding: 8px 12px;
  font-size: .85rem;
}

.bulk-value-input {
  max-width: 140px;
  padding: 8px 12px;
  font-size: .85rem;
}

.bulk-bar .btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

input:disabled, input[readonly] {
  opacity: .65;
  cursor: not-allowed;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: background .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform .2s, background .2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: rgba(20,184,166,.35);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: var(--accent);
}

.toggle-switch input:focus-visible + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(20,184,166,.25);
}

.toggle-switch.is-loading {
  opacity: .55;
  pointer-events: none;
}

.toggle-switch input:disabled + .toggle-slider {
  cursor: wait;
}

/* Responsive */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 220px;
  }

  .main-content {
    padding: 20px 16px 32px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
    padding: 16px 12px 32px;
  }

  .app-layout { flex-direction: column; }

  .page-header h1 { font-size: 1.25rem; }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    min-width: 900px;
    table-layout: auto;
  }
}
