:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.08);
  --min-touch: 44px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Header & Navigation */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 0.75rem 1rem;
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  gap: 1rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.025em;
}

.logo-tag {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

/* Hamburger button for mobile */
.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--min-touch);
  height: var(--min-touch);
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-main);
}

.menu-btn svg {
  width: 24px;
  height: 24px;
}

/* Desktop navigation */
.desktop-nav {
  display: none;
  align-items: center;
  gap: 1rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 0.95rem;
  transition: all 0.15s ease;
  min-height: var(--min-touch);
}

.nav-link:hover, .nav-link.active {
  color: var(--primary);
  background: var(--primary-light);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-main);
  background: var(--bg-main);
  padding: 0.4rem 0.8rem;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
}

.user-role-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 9999px;
  text-transform: uppercase;
  font-weight: 700;
}

.role-admin {
  background: #fee2e2;
  color: #b91c1c;
}

.role-user {
  background: #e0e7ff;
  color: #3730a3;
}

/* Drawer for mobile */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 280px;
  max-width: 85vw;
  background: #ffffff;
  z-index: 55;
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

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

.drawer-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  overflow-y: auto;
}

.drawer-footer {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Main Container */
.main-wrapper {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
  flex: 1;
}

/* Mobile Vertical Flow */
.vertical-flow {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Quota Banner */
.quota-banner {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-md);
}

.quota-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quota-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.85;
}

.quota-value {
  font-size: 1.85rem;
  font-weight: 800;
  line-height: 1.1;
}

.quota-sub {
  font-size: 0.85rem;
  opacity: 0.9;
}

.quota-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
}

.quota-pill-label {
  opacity: 0.8;
}

.quota-pill-val {
  font-weight: 700;
  font-size: 0.9rem;
}

/* Dropzone */
.dropzone {
  border: 2px dashed #93c5fd;
  background: #f0f7ff;
  border-radius: var(--radius-md);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: #e0f2fe;
}

.dropzone-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
}

.dropzone-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}

.dropzone-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* File Selected Card */
.file-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-md);
  gap: 1rem;
}

.file-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow: hidden;
}

.file-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge-pages {
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.75rem;
}

/* Touch Stepper for Copies */
.stepper-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.stepper-btn {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  min-height: var(--min-touch);
  min-width: var(--min-touch);
}

.stepper-btn:active {
  background: #e2e8f0;
}

.stepper-input {
  width: 90px;
  height: 52px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: white;
}

/* Printers Grid */
.printer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.printer-card {
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: all 0.15s ease;
  min-height: var(--min-touch);
}

.printer-card:hover {
  border-color: #93c5fd;
}

.printer-card.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

.printer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.printer-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.status-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 9999px;
  font-weight: 600;
}

.status-online {
  background: #dcfce7;
  color: #15803d;
}

.status-offline {
  background: #f1f5f9;
  color: #64748b;
}

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  min-height: var(--min-touch);
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text-main);
  outline: none;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--min-touch);
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
}

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

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

.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f1f5f9;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

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

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  min-width: var(--min-touch);
  min-height: var(--min-touch);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 1.25rem 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Breakdown list in confirmation modal */
.summary-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px dashed var(--border-color);
}

.summary-total {
  font-size: 1.1rem;
  font-weight: 700;
  border-top: 2px solid var(--border-color);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

/* Tables & Mobile Card Transformations (< 768px) */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-muted);
  font-weight: 600;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

@media (max-width: 768px) {
  .desktop-nav {
    display: none !important;
  }
  .menu-btn {
    display: flex;
  }

  /* Transform table into cards */
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    display: none;
  }

  .data-table tr {
    background: white;
    margin-bottom: 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem;
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
  }

  .data-table td:last-child {
    border-bottom: none;
    padding-top: 0.6rem;
  }

  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: left;
    margin-right: 1rem;
  }
}

@media (min-width: 769px) {
  .desktop-nav {
    display: flex;
  }
  .menu-btn {
    display: none;
  }
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  left: 1rem;
  max-width: 420px;
  margin-left: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: white;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--primary);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  pointer-events: auto;
  animation: slideIn 0.25s ease;
}

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

.toast-error {
  border-left-color: var(--danger);
}

@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Admin Dashboard Metrics Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.metric-card {
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
}

/* Tabs */
.tab-bar {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
  gap: 0.5rem;
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  min-height: var(--min-touch);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Utility classes */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }
.font-bold { font-weight: 700; }
