/* ==========================================================================
   MachinistZen MachinistZen - Shared Theme
   Aligned with the customer brand.
   Palette: copper / silver / cream.
   Light theme; canonical mark at /assets/icons/pwa/icon-192.svg.
   Last refresh 2026-05-07.
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  /* Backgrounds — clean shop-floor cream/white */
  --bg-primary: #FFFFFF;
  --bg-secondary: #FAFBFC;
  --bg-card: #FFFFFF;
  --bg-sidebar: #1f2937;        /* charcoal — replaces navy #003366 */
  --bg-hover: #F4F2EE;          /* warm cream hover (was cold blue-tinted) */
  --bg-active: #F7EFE3;         /* faint copper wash */

  /* Text */
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #9CA3AF;
  --text-inverse: #FFFFFF;

  /* Brand Accents — copper + silver */
  --accent-primary: #B8754A;    /* MachinistZen copper "M" */
  --accent-dark: #9A6440;       /* hover/active copper */
  --accent-bronze: #B8754A;     /* alias kept for legacy callers */
  --accent-steel: #6B7378;      /* silver-dark */
  --accent-light: #F7EFE3;      /* faint copper background wash */

  /* Status (professional, not neon) */
  --status-running: #1b9e4f;    /* slightly darker green for white-bg contrast */
  --status-idle: #C77E1A;
  --status-alarm: #d92929;
  --status-maintenance: #C77E1A;
  --status-offline: #9aa6b8;

  /* Borders & Shadows */
  --border-light: #E5E7EB;
  --border-medium: #D1D5DB;
  --border-focus: #B8754A;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --shadow-card-hover: 0 8px 24px rgba(184,117,74,0.15);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Bot System */
  --bot-purple: #7C3AED;
  --tier-owner: #D97706;
  --tier-manager: #0066CC;
  --tier-department: #7C3AED;
  --connection-active: #4CAF50;
  --connection-pending: #D97706;
  --connection-broken: #F44336;
  --connection-blocked: #9E9E9E;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 350ms ease;

  /* Layout */
  --container-max: 1400px;
  --sidebar-width: 260px;
  --header-height: 60px;
}

/* ---------- Base Reset ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

img, svg {
  max-width: 100%;
  display: block;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent-primary); }
.text-success { color: var(--status-running); }
.text-warning { color: var(--status-idle); }
.text-danger { color: var(--status-alarm); }

/* ---------- Layout Containers ---------- */
.mz-container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.mz-page {
  padding: var(--space-xl);
  min-height: 100vh;
}

.mz-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.mz-page-header h1 {
  color: var(--accent-dark);
}

/* ---------- Card Component ---------- */
.mz-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}

.mz-card:hover {
  box-shadow: var(--shadow-md);
}

.mz-card-clickable {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.mz-card-clickable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  text-decoration: none;
  color: inherit;
}

.mz-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-light);
}

.mz-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------- Button System ---------- */
.mz-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.5;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.mz-btn:hover {
  text-decoration: none;
}

.mz-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mz-btn-primary {
  background: var(--accent-primary);
  color: var(--text-inverse);
  border-color: var(--accent-primary);
}

.mz-btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: var(--text-inverse);
}

.mz-btn-secondary {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.mz-btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-medium);
}

.mz-btn-danger {
  background: var(--status-alarm);
  color: var(--text-inverse);
  border-color: var(--status-alarm);
}

.mz-btn-danger:hover:not(:disabled) {
  background: #D32F2F;
  border-color: #D32F2F;
  color: var(--text-inverse);
}

.mz-btn-success {
  background: var(--status-running);
  color: var(--text-inverse);
  border-color: var(--status-running);
}

.mz-btn-success:hover:not(:disabled) {
  background: #388E3C;
  border-color: #388E3C;
  color: var(--text-inverse);
}

.mz-btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
}

.mz-btn-lg {
  padding: 0.75rem 2rem;
  font-size: 1rem;
}

.mz-btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* ---------- Form Elements ---------- */
.mz-input,
.mz-select,
.mz-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.mz-input:focus,
.mz-select:focus,
.mz-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

.mz-input::placeholder {
  color: var(--text-muted);
}

.mz-textarea {
  resize: vertical;
  min-height: 80px;
}

.mz-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.mz-form-group {
  margin-bottom: var(--space-md);
}

/* ---------- Table Styles ---------- */
.mz-table-container {
  overflow-x: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}

.mz-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.mz-table th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--border-light);
  white-space: nowrap;
}

.mz-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

.mz-table tbody tr:hover {
  background: var(--bg-hover);
}

.mz-table tbody tr:last-child td {
  border-bottom: none;
}

/* ---------- Tab Navigation ---------- */
.mz-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-light);
  margin-bottom: var(--space-lg);
  overflow-x: auto;
}

.mz-tab {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.mz-tab:hover {
  color: var(--accent-primary);
  background: var(--bg-hover);
}

.mz-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  font-weight: 600;
}

/* ---------- Stat Cards ---------- */
.mz-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.mz-stat {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
}

.mz-stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.mz-stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.mz-stat-change {
  font-size: 0.8rem;
  margin-top: var(--space-xs);
}

.mz-stat-change.positive { color: var(--status-running); }
.mz-stat-change.negative { color: var(--status-alarm); }

/* ---------- Status Badges ---------- */
.mz-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.mz-badge-running {
  background: rgba(76, 175, 80, 0.12);
  color: #2E7D32;
}

.mz-badge-idle {
  background: rgba(255, 167, 38, 0.12);
  color: #E65100;
}

.mz-badge-alarm {
  background: rgba(244, 67, 54, 0.12);
  color: #C62828;
}

.mz-badge-maintenance {
  background: rgba(255, 152, 0, 0.12);
  color: #E65100;
}

.mz-badge-offline {
  background: rgba(158, 158, 158, 0.12);
  color: #616161;
}

.mz-badge-info {
  background: rgba(0, 102, 204, 0.1);
  color: var(--accent-primary);
}

.mz-badge-success {
  background: rgba(76, 175, 80, 0.12);
  color: #2E7D32;
}

.mz-badge-warning {
  background: rgba(255, 152, 0, 0.12);
  color: #E65100;
}

.mz-badge-danger {
  background: rgba(244, 67, 54, 0.12);
  color: #C62828;
}

/* ---------- Modal Overlay ---------- */
.mz-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-lg);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.mz-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.mz-modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-xl);
}

.mz-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-light);
}

.mz-modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  transition: all var(--transition-fast);
}

.mz-modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.mz-modal-footer {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-light);
}

/* ---------- Page Header Bar ---------- */
.mz-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  padding: 0 var(--space-lg);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.mz-header-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
}

.mz-header-brand:hover {
  text-decoration: none;
  color: var(--accent-primary);
}

.mz-header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.mz-header-link {
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.mz-header-link:hover {
  background: var(--bg-hover);
  color: var(--accent-primary);
  text-decoration: none;
}

/* ---------- Search Input ---------- */
.mz-search {
  position: relative;
}

.mz-search input {
  padding-left: 2.5rem;
}

.mz-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* ---------- Progress Bar ---------- */
.mz-progress {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.mz-progress-bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  transition: width var(--transition-base);
}

.mz-progress-bar.success { background: var(--status-running); }
.mz-progress-bar.warning { background: var(--status-idle); }
.mz-progress-bar.danger { background: var(--status-alarm); }

/* ---------- Empty State ---------- */
.mz-empty {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.mz-empty-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

/* ---------- Toast / Alert ---------- */
.mz-alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid;
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
}

.mz-alert-info {
  background: rgba(0, 102, 204, 0.08);
  border-color: rgba(0, 102, 204, 0.2);
  color: var(--accent-primary);
}

.mz-alert-success {
  background: rgba(76, 175, 80, 0.08);
  border-color: rgba(76, 175, 80, 0.2);
  color: #2E7D32;
}

.mz-alert-warning {
  background: rgba(255, 152, 0, 0.08);
  border-color: rgba(255, 152, 0, 0.2);
  color: #E65100;
}

.mz-alert-danger {
  background: rgba(244, 67, 54, 0.08);
  border-color: rgba(244, 67, 54, 0.2);
  color: #C62828;
}

/* ---------- Utility Classes ---------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.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); }

.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Shared Tile Component ---------- */
.mz-tile {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.mz-tile:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
}

.mz-tile.selected {
  border-color: var(--accent-primary);
  background: var(--accent-light);
}

.mz-tile .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mz-tile .status-dot.active { background: var(--connection-active); }
.mz-tile .status-dot.pending { background: var(--connection-pending); }
.mz-tile .status-dot.broken { background: var(--connection-broken); }
.mz-tile .status-dot.offline { background: var(--status-offline); }

.mz-tile.employee-tile {
  border-left: 3px solid var(--tier-manager);
}

.mz-tile.owner-tile {
  border-left: 3px solid var(--tier-owner);
}

.mz-tile.bot-tile {
  border-left: 3px solid var(--bot-purple);
  background: rgba(124, 58, 237, 0.05);
}

.mz-tile.bot-tile:hover {
  background: rgba(124, 58, 237, 0.10);
  border-color: var(--bot-purple);
}

/* ---------- Grid Utilities ---------- */
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Responsive Breakpoints ---------- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root {
    --space-xl: 1.5rem;
    --space-2xl: 2rem;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .mz-page { padding: var(--space-md); }

  .mz-page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .mz-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-4, .grid-3, .grid-2 {
    grid-template-columns: 1fr;
  }

  .mz-modal {
    max-width: 100%;
    margin: var(--space-md);
  }

  .mz-header {
    padding: 0 var(--space-md);
  }

  .mz-tabs {
    gap: 0;
  }

  .mz-tab {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .mz-stats {
    grid-template-columns: 1fr;
  }

  .mz-modal-footer {
    flex-direction: column;
  }

  .mz-modal-footer .mz-btn {
    width: 100%;
  }
}

/* Touch-friendly targets */
@media (pointer: coarse) {
  .mz-btn {
    min-height: 44px;
    padding: 0.625rem 1.25rem;
  }

  .mz-tab {
    min-height: 44px;
  }

  .mz-input,
  .mz-select {
    min-height: 44px;
  }
}

/* ---------- Loading Spinner ---------- */
.mz-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: mz-spin 0.8s linear infinite;
}

@keyframes mz-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Scrollbar Styling ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
