@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ============================================================
   FACTORY MANAGER — Modern Design System
   Clean light theme with collapsible sidebar layout
   ============================================================ */

/* --- Design Tokens --- */
:root {
  /* Colors */
  --color-bg: #f1f5f9;
  --color-surface: #ffffff;
  --color-surface-hover: #f8fafc;
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --color-text: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-primary-text: #ffffff;
  --color-success: #059669;
  --color-success-light: #ecfdf5;
  --color-success-border: #a7f3d0;
  --color-warning: #d97706;
  --color-warning-light: #fffbeb;
  --color-warning-border: #fde68a;
  --color-danger: #dc2626;
  --color-danger-light: #fef2f2;
  --color-danger-border: #fecaca;
  --color-info: #0284c7;
  --color-info-light: #f0f9ff;

  /* Sidebar */
  --sidebar-width: 248px;
  --sidebar-collapsed-width: 64px;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e2e8f0;
  --sidebar-item-hover: #f1f5f9;
  --sidebar-item-active: #eff6ff;
  --sidebar-item-active-text: #2563eb;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  /* Typography */
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-lg: 1rem;
  --text-xl: 1.125rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code, pre, .mono {
  font-family: var(--font-mono);
}

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

/* --- App Layout (Sidebar + Content) --- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition-slow);
  padding: var(--space-2xl);
}

body.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: width var(--transition-slow);
  overflow: hidden;
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-lg);
  height: 60px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand-icon svg {
  width: 18px;
  height: 18px;
  color: white;
}

.sidebar-brand-text {
  font-weight: 700;
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition-base);
}

body.sidebar-collapsed .sidebar-brand-text {
  opacity: 0;
  width: 0;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-sm) var(--space-sm);
}

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-lg) var(--space-sm) var(--space-xs) var(--space-md);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition-base);
}

body.sidebar-collapsed .sidebar-section-label {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  margin-bottom: 2px;
  position: relative;
}

.sidebar-item:hover {
  background: var(--sidebar-item-hover);
  color: var(--color-text);
}

.sidebar-item.active {
  background: var(--sidebar-item-active);
  color: var(--sidebar-item-active-text);
  font-weight: 600;
}

.sidebar-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-item.active svg {
  opacity: 1;
}

.sidebar-item-label {
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition-base);
}

body.sidebar-collapsed .sidebar-item-label {
  opacity: 0;
  width: 0;
}

body.sidebar-collapsed .sidebar-item {
  justify-content: center;
  padding: var(--space-sm);
}

/* Tooltip on collapsed hover */
body.sidebar-collapsed .sidebar-item[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-text);
  color: white;
  font-size: var(--text-xs);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 9999;
  pointer-events: none;
}

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: var(--space-md);
  flex-shrink: 0;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
  background: var(--sidebar-item-hover);
  color: var(--color-text);
}

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
  transition: transform var(--transition-slow);
}

body.sidebar-collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

.sidebar-toggle-label {
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition-base);
}

body.sidebar-collapsed .sidebar-toggle-label {
  opacity: 0;
  width: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.sidebar-user:hover {
  background: var(--sidebar-item-hover);
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.sidebar-user-info {
  overflow: hidden;
  white-space: nowrap;
  opacity: 1;
  transition: opacity var(--transition-base);
}

body.sidebar-collapsed .sidebar-user-info {
  opacity: 0;
  width: 0;
}

.sidebar-user-name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.sidebar-user-role {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* --- Page Header --- */
.page-header {
  margin-bottom: var(--space-2xl);
}

.page-header h1 {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.3;
}

.page-header p {
  margin: var(--space-xs) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

/* --- Cards --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin: var(--space-xs) 0 0;
}

/* --- Buttons --- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.5;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

button:hover, .btn:hover {
  background: var(--color-surface-hover);
  border-color: #cbd5e1;
}

button:active, .btn:active {
  transform: translateY(1px);
}

button:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

button.primary, .btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-text);
}

button.primary:hover, .btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

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

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

button.ghost:hover, .btn-ghost:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

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

button.danger:hover, .btn-danger:hover {
  background: #b91c1c;
}

button.sm {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-xs);
}

/* --- Inputs & Forms --- */
input, textarea, select {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input::placeholder, textarea::placeholder {
  color: var(--color-text-muted);
}

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

label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

label span {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xs);
}

/* --- Tables --- */
.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

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

th {
  text-align: left;
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-sm);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: top;
}

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

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

tr[onclick], tr[style*="cursor:pointer"], tr.clickable {
  cursor: pointer;
}

/* --- Badges & Pills --- */
.badge, .pill, .status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-default, .pill {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.badge-success, .pill.ok, .status-accepted {
  background: var(--color-success-light);
  color: var(--color-success);
  border: 1px solid var(--color-success-border);
}

.badge-warning, .pill.warn, .status-sent {
  background: var(--color-warning-light);
  color: var(--color-warning);
  border: 1px solid var(--color-warning-border);
}

.badge-danger {
  background: var(--color-danger-light);
  color: var(--color-danger);
  border: 1px solid var(--color-danger-border);
}

.badge-info, .status-draft {
  background: var(--color-info-light);
  color: var(--color-info);
  border: 1px solid #bae6fd;
}

.badge-primary {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border: 1px solid #bfdbfe;
}

/* --- Grid System --- */
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}

.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
}

.grid4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-lg);
}

.row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-sm);
}

.col-1 { grid-column: span 1; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; }
.col-10 { grid-column: span 10; }
.col-11 { grid-column: span 11; }
.col-12 { grid-column: span 12; }

/* --- Flex Utilities --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }

/* --- Spacing --- */
.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.mb-2xl { margin-bottom: var(--space-2xl); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }

/* --- Text --- */
.text-muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-mono { font-family: var(--font-mono); }

/* --- Status --- */
.status {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
  white-space: pre-wrap;
}

.status.error {
  color: var(--color-danger);
  font-weight: 600;
}

.status.success {
  color: var(--color-success);
  font-weight: 600;
}

/* --- Stat Cards --- */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-xs);
  transition: all var(--transition-base);
}

.stat-card:hover {
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.stat-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}

.stat-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--space-md);
  font-size: var(--text-sm);
  color: var(--color-primary);
  font-weight: 500;
  text-decoration: none;
  transition: color var(--transition-fast);
}

.stat-link:hover {
  color: var(--color-primary-hover);
}

/* --- Action Cards --- */
.action-card {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-xl);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--color-text);
  transition: all var(--transition-base);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
}

.action-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  color: var(--color-text);
}

.action-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-xl);
  font-weight: 700;
}

.action-icon.blue { background: #eff6ff; color: #2563eb; }
.action-icon.green { background: #ecfdf5; color: #059669; }
.action-icon.purple { background: #f5f3ff; color: #7c3aed; }
.action-icon.amber { background: #fffbeb; color: #d97706; }
.action-icon.rose { background: #fff1f2; color: #e11d48; }
.action-icon.cyan { background: #ecfeff; color: #0891b2; }

.action-title {
  font-weight: 600;
  font-size: var(--text-sm);
  margin-bottom: 2px;
}

.action-desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* --- Modals --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  padding: var(--space-xl);
}

.modal.open {
  display: flex;
}

.modal .card {
  width: 720px;
  max-width: 96vw;
  max-height: 80vh;
  overflow: auto;
  box-shadow: var(--shadow-xl);
}

/* --- Section headers --- */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
}

.section-header h3, .section-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 600;
}

/* --- Actions bar --- */
.actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-top: var(--space-md);
}

/* --- Panel (form sections) --- */
.panel {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.panel h4 {
  margin: 0 0 var(--space-md) 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Toolbar --- */
.toolbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
}

.toolbar button {
  min-height: 36px;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
  .grid4 { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
    padding: var(--space-lg);
  }

  .grid2, .grid3, .grid4 {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .col-1, .col-2, .col-3, .col-4, .col-5, .col-6,
  .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 {
    grid-column: span 1;
  }

  .mobile-menu-btn {
    display: flex !important;
  }
}

/* Mobile menu button (hidden by default) */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  color: var(--color-text);
}

/* --- Output/Pre --- */
.output, pre.output {
  margin: 0;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  overflow: auto;
  max-height: 420px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* --- Link --- */
.link {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
}

.link:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

/* --- Empty states --- */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-muted);
}

.empty-state p {
  margin: var(--space-sm) 0 0;
  font-size: var(--text-sm);
}

/* --- Wrap / container --- */
.wrap, .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-xl);
}

/* --- Top bar (legacy compat for pages with .top) --- */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
  padding: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* --- Print --- */
@media print {
  .sidebar, .sidebar-toggle, .mobile-menu-btn { display: none !important; }
  .main-content { margin-left: 0 !important; }
}

/* --- Loading spinner --- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Transaction Record Shell
   Shared pattern for all record/detail pages (invoices,
   purchase orders, bills, quotes, work orders, etc.)
   ============================================================ */

/* --- 1. Record Header --- */
.record-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: white;
  border-bottom: 1px solid var(--color-border);
}

.record-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.record-status {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.record-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

/* --- 2. Record Meta Grid --- */
.record-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.record-meta-item label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.record-meta-item .value {
  font-size: 0.9375rem;
  font-weight: 500;
}

/* --- 3. Record Sections --- */
.record-section {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
}

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

.record-section-body {
  padding: 1.5rem;
}

/* --- 4. Line Items Table --- */
.record-lines {
  width: 100%;
  border-collapse: collapse;
}

.record-lines th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--color-bg);
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
}

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

.record-lines .line-total {
  text-align: right;
  font-weight: 600;
}

/* --- 5. Record Totals --- */
.record-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 1rem 1.5rem;
  gap: 0.5rem;
}

.record-totals .total-row {
  display: flex;
  gap: 2rem;
  min-width: 250px;
  justify-content: space-between;
}

.record-totals .total-row.grand {
  font-size: 1.125rem;
  font-weight: 700;
  border-top: 2px solid var(--color-border);
  padding-top: 0.5rem;
}

/* --- 6. Payment History --- */
.record-payments {
  width: 100%;
  border-collapse: collapse;
}

.record-payments th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--color-bg);
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
}

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

/* --- 7. Activity Timeline --- */
.record-timeline {
  padding: 1rem 1.5rem;
}

.record-timeline-item {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 0;
  position: relative;
}

.record-timeline-item::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 2rem;
  bottom: -0.75rem;
  width: 2px;
  background: var(--color-border);
}

.record-timeline-item:last-child::before {
  display: none;
}

.record-timeline-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

.record-timeline-content {
  flex: 1;
}

.record-timeline-date {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* --- 8. Attachment Section --- */
.record-attachments {
  padding: 1rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* --- 9. Status Badges (unified) --- */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-draft {
  background: #f3f4f6;
  color: #6b7280;
}

.status-open {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-paid {
  background: #d1fae5;
  color: #059669;
}

.status-void {
  background: #fef2f2;
  color: #dc2626;
}

.status-overdue {
  background: #fef3c7;
  color: #d97706;
}

.status-approved {
  background: #d1fae5;
  color: #059669;
}

.status-partial {
  background: #fef3c7;
  color: #d97706;
}

.status-synced {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-error {
  background: #fef2f2;
  color: #dc2626;
}

/* --- 10. Action Dropdown (shared) --- */
.action-dropdown {
  position: relative;
  display: inline-block;
}

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

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

.action-dropdown-item {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.action-dropdown-divider {
  border-top: 1px solid var(--color-border);
  margin: 0.25rem 0;
}

