/* ─────────────────────────────────────────────────────────────
   GMAO — Industrial Dark UI  |  IBM Plex Sans + IBM Plex Mono
   ───────────────────────────────────────────────────────────── */

:root {
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --bg-base: #0d1117;
  --bg-surface: #161b22;
  --bg-card: #1c2128;
  --bg-card-hover: #21262d;
  --border: #30363d;
  --border-subtle: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #a7b0ba;
  --text-muted: #7d8793;
  --accent-blue: #2f81f7;
  --accent-blue-dim: #1f4d91;
  --accent-green: #3fb950;
  --accent-yellow: #d29922;
  --accent-red: #f85149;
  --accent-orange: #db6d28;
  --accent-purple: #8957e5;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --font: 'Segoe UI', Arial, sans-serif;
  --mono: 'Cascadia Mono', Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  display: flex;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  padding: 0 0 16px;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.brand-icon { font-size: 22px; color: var(--accent-blue); animation: spin 12s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.brand-name { display: block; font-weight: 700; font-size: 15px; color: var(--text-primary); letter-spacing: .5px; }
.brand-sub  { display: block; font-size: 10px; color: var(--text-muted); font-family: var(--mono); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-section {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 8px 16px 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: 0;
  transition: color .15s, background .15s;
  position: relative;
}
.sidebar-link:hover { background: var(--bg-card); color: var(--text-primary); }
.sidebar-link.active {
  color: var(--accent-blue);
  background: rgba(47, 129, 247, .1);
  border-left: 2px solid var(--accent-blue);
}
.sidebar-link.active i { color: var(--accent-blue); }
.sidebar-link i { font-size: 14px; width: 16px; text-align: center; }

.emergency-link { color: var(--accent-red) !important; }
.emergency-link:hover { background: rgba(248, 81, 73, .1) !important; }

.sidebar-footer { margin-top: auto; padding: 16px 16px 0; border-top: 1px solid var(--border); }
.footer-version { font-size: .7rem; }
.current-user { align-items: center; gap: 6px; max-width: 240px; color: var(--text-secondary); font-size: 12px; }
.current-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.machine-navigation-card { cursor: pointer; transition: border-color .2s, transform .15s; }
.machine-navigation-card:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.status-wrapper { position: relative; display: inline-block; }
button.badge-status { border: 0; cursor: pointer; }
.status-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1000;
  min-width: 210px;
  padding: 6px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.3);
}
.status-menu.open { display: block; }
.status-menu-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  transition: background .15s;
}
.status-menu-item:not(:disabled):hover,
.status-menu-item:not(:disabled):focus-visible { background: rgba(47,129,247,.1); }
.status-menu-item:disabled { cursor: not-allowed; color: var(--text-muted); opacity: .5; }

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  width: calc(100% - var(--sidebar-w));
  max-width: calc(100% - var(--sidebar-w));
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-weight: 600; font-size: 15px; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

.page-content { width: 100%; max-width: 100%; min-width: 0; padding: 24px; overflow-x: hidden; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-body { padding: 16px; }
.card-body.p-0 { display: block; max-width: 100%; overflow-x: auto; }

/* ── Stat cards ───────────────────────────────────────────── */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: border-color .2s, background .2s;
}
.stat-card:hover { border-color: var(--accent-blue); background: var(--bg-card-hover); }

.stat-card-link {
  display: block;
  text-decoration: none;
  cursor: pointer;
  color: inherit;
}
.stat-card-link:hover .stat-card {
  border-color: var(--accent-blue);
  background: var(--bg-card-hover);
}

.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(47,129,247,.15); color: var(--accent-blue); }
.stat-icon.green  { background: rgba(63,185,80,.15);  color: var(--accent-green); }
.stat-icon.red    { background: rgba(248,81,73,.15);  color: var(--accent-red); }
.stat-icon.yellow { background: rgba(210,153,34,.15); color: var(--accent-yellow); }
.stat-icon.purple { background: rgba(137,87,229,.15); color: var(--accent-purple); }
.stat-icon.orange { background: rgba(219,109,40,.15); color: var(--accent-orange); }

.stat-value { font-size: 28px; font-weight: 700; line-height: 1; font-family: var(--mono); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Tables ───────────────────────────────────────────────── */
.table {
  color: var(--text-primary);
  font-size: 13px;
  --bs-table-bg: transparent;
  --bs-table-striped-bg: rgba(255,255,255,.02);
  --bs-table-hover-bg: rgba(47,129,247,.05);
  --bs-table-border-color: var(--border);
}
.table thead th {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
}
.table td { padding: 10px 12px; vertical-align: middle; border-color: var(--border-subtle); }

/* ── Badges ───────────────────────────────────────────────── */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
}
.badge-operational  { background: rgba(63,185,80,.15);  color: var(--accent-green); }
.badge-maintenance  { background: rgba(210,153,34,.15); color: var(--accent-yellow); }
.badge-pendingrepair{ background: rgba(248,81,73,.15);  color: var(--accent-red); }
.badge-outofservice { background: rgba(139,148,158,.15);color: var(--text-secondary); }

.badge-pending    { background: rgba(139,148,158,.15); color: var(--text-secondary); }
.badge-inprogress { background: rgba(47,129,247,.15);  color: var(--accent-blue); }
.badge-completed  { background: rgba(63,185,80,.15);   color: var(--accent-green); }
.badge-cancelled  { background: rgba(139,148,158,.1);  color: var(--text-muted); }
.badge-approval   { background: rgba(210,153,34,.15); color: var(--accent-yellow); }

.badge-planned    { background: rgba(47,129,247,.15);  color: var(--accent-blue); }
.badge-emergency  { background: rgba(248,81,73,.15);   color: var(--accent-red);  animation: pulse-border .8s ease-in-out infinite; }
.badge-inspection { background: rgba(137,87,229,.15);  color: var(--accent-purple); }
.badge-repair     { background: rgba(219,109,40,.15);  color: var(--accent-orange); }

.badge-low      { background: rgba(63,185,80,.12);  color: var(--accent-green); }
.badge-normal   { background: rgba(47,129,247,.12); color: var(--accent-blue); }
.badge-high     { background: rgba(210,153,34,.15); color: var(--accent-yellow); }
.badge-critical { background: rgba(248,81,73,.2);   color: var(--accent-red); font-weight:700; }

@keyframes pulse-border { 0%,100%{box-shadow:0 0 0 0 rgba(248,81,73,.4)} 50%{box-shadow:0 0 0 4px rgba(248,81,73,0)} }

/* ── Forms ────────────────────────────────────────────────── */
.form-control, .form-select {
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  font-size: 13px;
}
.form-control:focus, .form-select:focus {
  background: var(--bg-base);
  border-color: var(--accent-blue);
  color: var(--text-primary);
  box-shadow: 0 0 0 3px rgba(47,129,247,.2);
}
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.form-text  { font-size: 11px; color: var(--text-muted); }
.form-control::placeholder { color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn { font-size: 13px; font-weight: 500; border-radius: var(--radius); }
.btn-primary { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.btn-primary:hover { background: #388bfd; border-color: #388bfd; }
.btn-danger  { background: var(--accent-red); border-color: var(--accent-red); color: #fff; }
.btn-success { background: var(--accent-green); border-color: var(--accent-green); color: #fff; }
.btn-outline-secondary { border-color: var(--border); color: var(--text-secondary); }
.btn-outline-secondary:hover { background: var(--bg-card); color: var(--text-primary); border-color: var(--border); }

/* ── Machine image ────────────────────────────────────────── */
.machine-img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.machine-img-placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 48px;
}
.machine-thumb {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ── Timeline ─────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content:''; position:absolute; left:7px; top:0; bottom:0; width:2px; background:var(--border); }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-dot {
  position: absolute;
  left: -21px; top: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-card);
}
.timeline-dot.completed { background: var(--accent-green); border-color: var(--accent-green); }
.timeline-dot.emergency { background: var(--accent-red);   border-color: var(--accent-red); }
.timeline-dot.planned   { background: var(--accent-blue);  border-color: var(--accent-blue); }
.timeline-dot.inprogress{ background: var(--accent-yellow);border-color: var(--accent-yellow); }
.timeline-content { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.timeline-date { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.timeline-title { font-weight: 600; font-size: 13px; }

/* ── Misc ─────────────────────────────────────────────────── */
.mono { font-family: var(--mono); }
.text-dim { color: var(--text-muted); }
.page-header { margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 20px; font-weight: 700; margin: 0; }
.detail-grid { display: grid; gap: 6px; }
.detail-row { display: flex; gap: 12px; font-size: 13px; }
.detail-label { min-width: 140px; color: var(--text-secondary); font-weight: 600; font-size: 12px; }
.separator { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.emergency-banner {
  background: rgba(248,81,73,.1);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-red);
  font-weight: 600;
  margin-bottom: 16px;
}

/* ── Status Dropdowns ────────────────────────────────────────── */
.status-dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.status-badge-btn {
  display: inline-block;
}

.status-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 1000;
  min-width: 220px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.status-menu-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  clear: both;
  font-weight: 400;
  color: var(--text-primary);
  text-align: left;
  white-space: nowrap;
  background-color: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
  font-size: 13px;
}

.status-menu-item:hover:not(.disabled) {
  background-color: rgba(47, 129, 247, 0.1);
  color: var(--accent-blue);
}

.status-menu-item.disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.status-menu-item.disabled:hover {
  background-color: transparent;
  color: var(--text-muted);
}

/* ── Dropdowns ────────────────────────────────────────── */
.dropdown-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  clear: both;
  font-weight: 400;
  color: var(--text-primary);
  text-align: inherit;
  white-space: nowrap;
  background-color: transparent;
  border: 0;
  cursor: pointer;
  transition: background-color 0.2s;
}

.dropdown-item:hover:not(.disabled) {
  background-color: rgba(47, 129, 247, 0.1);
  color: var(--accent-blue);
}

.dropdown-item.disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.dropdown-item.disabled:hover {
  background-color: transparent;
  color: var(--text-muted);
}

.dropdown-menu {
  background-color: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
  padding: 0.5rem 0 !important;
}

/* Alerts override */
.alert { border-radius: var(--radius); font-size: 13px; }
.alert-success { background: rgba(63,185,80,.1);  border-color: rgba(63,185,80,.3);  color: var(--accent-green); }
.alert-warning { background: rgba(210,153,34,.1); border-color: rgba(210,153,34,.3); color: var(--accent-yellow); }
.alert-danger  { background: rgba(248,81,73,.1);  border-color: rgba(248,81,73,.3);  color: var(--accent-red); }

/* Responsive */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.5); }
  .main-content { margin-left: 0; width: 100%; max-width: 100vw; }
  .stat-value { font-size: 22px; }
}

@media (max-width: 576px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding-left: 10px; padding-right: 10px; }
  .page-content { padding: 20px 12px; }
  .page-header { align-items: flex-start; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Authentication and user access */
.auth-body {
  display: block;
  min-height: 100%;
  background:
    radial-gradient(circle at 15% 10%, rgba(47,129,247,.16), transparent 35%),
    radial-gradient(circle at 90% 85%, rgba(137,87,229,.12), transparent 32%),
    var(--bg-base);
}
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.auth-card {
  width: min(100%, 430px);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(22,27,34,.96);
  box-shadow: 0 24px 80px rgba(0,0,0,.45);
}
.auth-card-wide { width: min(100%, 520px); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-brand-icon,
.auth-state-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  font-size: 21px;
}
.auth-brand-icon.warning { background: linear-gradient(135deg, var(--accent-yellow), var(--accent-orange)); }
.auth-product { font-weight: 700; font-size: 15px; }
.auth-subtitle { color: var(--text-muted); font-size: 12px; }
.auth-card h1 { margin: 0 0 8px; font-size: 24px; }
.auth-intro { margin-bottom: 24px; color: var(--text-secondary); }
.auth-submit { min-height: 44px; font-weight: 600; }
.auth-security-note {
  display: flex;
  gap: 9px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
}
.auth-state-icon { margin: 0 auto 20px; width: 58px; height: 58px; font-size: 27px; }
.auth-state-icon.danger { background: linear-gradient(135deg, var(--accent-red), var(--accent-orange)); }
.password-requirements {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid rgba(47,129,247,.28);
  border-radius: var(--radius);
  background: rgba(47,129,247,.08);
  color: var(--text-secondary);
  font-size: 12px;
}
.password-requirements strong { color: var(--text-primary); }
.security-summary { border-color: rgba(47,129,247,.3); background: rgba(47,129,247,.08); color: var(--text-secondary); }
.user-count { font-size: 11px; }
.supplier-line-comments { font-size: 12px; color: var(--text-secondary); }
.text-danger.field-validation-error { display: block; margin-top: 4px; font-size: 11px; }

@media (max-width: 576px) {
  .auth-shell { padding: 16px 10px; align-items: start; }
  .auth-card { margin-top: 12px; padding: 24px 20px; }
}
