/* ============================================
   DESIGN SYSTEM TOKENS
   ============================================ */

:root {
  /* COLORS - Core Palette */
  --color-primary: #0D4F68;
  --color-primary-dark: #09384D;
  --color-primary-light: #1A6B8A;
  --color-surface: #FAFAFA;
  --color-surface-elevated: #FFFFFF;
  --color-text: #1A1A1A;
  --color-text-secondary: #5C5C5C;
  --color-text-tertiary: #9CA3AF;
  --color-border: #E0E0E0;
  --color-border-light: #F0F0F0;

  /* COLORS - Semantic */
  --color-success: #2D6A4F;
  --color-success-bg: #E8F5E9;
  --color-warning: #E76F51;
  --color-warning-bg: #FFF3E0;
  --color-error: #C62828;
  --color-error-bg: #FFEBEE;
  --color-info: #1976D2;
  --color-info-bg: #E3F2FD;

  /* COLORS - Carriers */
  --color-correios: #1565C0;
  --color-correios-bg: #E3F2FD;
  --color-j3: #6B21A8;
  --color-j3-bg: #F3E5F5;

  /* TYPOGRAPHY - IBM Plex Sans */
  --font-display: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', 'Consolas', monospace;

  /* TYPOGRAPHY - Scale */
  --font-size-display: 32px;
  --font-size-h1: 24px;
  --font-size-h2: 20px;
  --font-size-h3: 16px;
  --font-size-body: 15px;
  --font-size-small: 13px;
  --font-size-tiny: 11px;
  --font-size-mono: 14px;

  /* TYPOGRAPHY - Weights */
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* TYPOGRAPHY - Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-loose: 1.75;

  /* SPACING - Base 4px */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* BORDER RADIUS */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  /* SHADOWS */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

  /* BREAKPOINTS */
  --breakpoint-mobile: 640px;
  --breakpoint-tablet: 768px;
  --breakpoint-desktop: 1024px;
  --breakpoint-wide: 1280px;

  /* TRANSITIONS */
  --transition-fast: 150ms ease-out;
  --transition-normal: 200ms ease-out;
  --transition-slow: 300ms ease-out;
}

/* ============================================
   BASE STYLES
   ============================================ */

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

body {
  font-family: var(--font-display);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-normal);
  color: var(--color-text);
  background: var(--color-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   LAYOUT
   ============================================ */

.app-container {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 180px;
  background: var(--color-primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  left: 0;
  top: 0;
  z-index: 100;
  transition: width var(--transition-normal);
}

.sidebar-header {
  padding: var(--space-6) var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .logo h1 {
  font-size: 16px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.5px;
  margin-bottom: var(--space-1);
}

.sidebar-header .logo p {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  font-weight: var(--font-weight-regular);
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
  font-size: 14px;
  font-weight: var(--font-weight-medium);
  gap: var(--space-3);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-left-color: white;
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-text {
  flex: 1;
}

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-item.logout {
  color: rgba(255, 107, 107, 0.8);
}

.nav-item.logout:hover {
  background: rgba(255, 107, 107, 0.1);
  color: #ff6b6b;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  margin-left: 180px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* HEADER */
.top-bar {
  background: var(--color-surface-elevated);
  height: 48px;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar h2 {
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.user-info {
  font-size: var(--font-size-small);
  color: var(--color-text-secondary);
}

/* CONTENT AREA */
.content-area {
  padding: var(--space-6);
  flex: 1;
  overflow-y: auto;
}

/* ============================================
   COMPONENTS
   ============================================ */

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

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

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

.btn-danger {
  background: var(--color-error);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #b71c1c;
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--color-surface);
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-small);
}

/* INPUTS */
.input,
.select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-body);
  font-family: var(--font-display);
  color: var(--color-text);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(13, 79, 104, 0.2);
}

.input::placeholder {
  color: var(--color-text-tertiary);
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-tiny);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.badge-correios {
  background: var(--color-correios-bg);
  color: var(--color-correios);
}

.badge-j3 {
  background: var(--color-j3-bg);
  color: var(--color-j3);
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-error {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.badge-info {
  background: var(--color-info-bg);
  color: var(--color-info);
}

/* TABLES */
.table-container {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--font-size-tiny);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-body);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border-light);
}

.data-table tr:hover td {
  background: var(--color-surface);
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* Checkbox cell */
.checkbox-cell {
  width: 40px;
  text-align: center;
}

/* Monospace for codes */
.mono {
  font-family: var(--font-mono);
  font-size: var(--font-size-mono);
}

/* Action cell */
.action-cell {
  white-space: nowrap;
  min-width: 120px;
}

.action-buttons {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

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

.dropdown-btn {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-small);
  color: var(--color-text);
  transition: all var(--transition-fast);
}

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

.dropdown-content {
  display: none;
  position: fixed;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 99999;
  padding: var(--space-2);
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.dropdown.show .dropdown-content {
  display: block;
}

.dropdown-section {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.dropdown-section:last-child {
  border-bottom: none;
}

.dropdown-section-title {
  font-size: var(--font-size-tiny);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--font-size-small);
  color: var(--color-text);
  transition: background var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--color-surface);
}

.dropdown-item.danger {
  color: var(--color-error);
}

.dropdown-item.danger:hover {
  background: var(--color-error-bg);
}

/* CARDS */
.card {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}

/* MODALS */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  animation: fadeIn var(--transition-fast);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--color-surface-elevated);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-5);
}

.modal-header h3 {
  font-size: var(--font-size-h1);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.modal-close:hover {
  background: var(--color-surface);
}

.modal-body {
  margin-bottom: var(--space-5);
}

.modal-footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* TOASTS */
.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.toast {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 400px;
  animation: slideIn var(--transition-normal);
}

.toast-success {
  border-left: 4px solid var(--color-success);
}

.toast-error {
  border-left: 4px solid var(--color-error);
}

.toast-warning {
  border-left: 4px solid var(--color-warning);
}

/* ANIMATIONS */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
  .sidebar {
    width: 60px;
  }

  .sidebar-header .logo h1,
  .sidebar-header .logo p,
  .nav-text {
    display: none;
  }

  .nav-icon {
    margin: 0;
  }

  .main-content {
    margin-left: 60px;
  }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   FOCUS STATES
   ============================================ */

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}
