:root {
  --bg-primary: #F8F9FA;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F1F3F5;
  --border-color: #E9ECEF;
  --border-hover: #DEE2E6;

  --brand-green: #2e7d32;
  --brand-blue: #4DADF7;
  --brand-dark: #212529;

  --accent-cyan: #339AF0;
  --accent-red: #C92A2A;
  --accent-red-bg: #FFF5F5;
  --accent-amber: #E67700;
  --accent-amber-bg: #FFF9DB;
  --accent-green-text: #0CA678;
  --accent-green-bg: #E6FCF5;
  --accent-blue-text: #1C7ED6;
  --accent-blue-bg: #E7F5FF;

  --text-main: #343A40;
  --text-muted: #6C757D;
  --text-light: #868E96;

  --font-sans: 'Plus Jakarta Sans', 'DM Sans', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* BAKERY HEADER NAV */
.bakery-navbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.4rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10000;
  box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo-img {
  height: 26px;
  width: auto;
}

.brand-meta {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 0.5rem;
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.branch-selector {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.nav-links-clean {
  display: flex;
  gap: 0.5rem;
}

.nav-link-clean {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  transition: all 0.2s;
}

.nav-link-clean:hover {
  color: var(--brand-dark);
  background: var(--bg-primary);
}

.nav-link-clean.active {
  color: var(--brand-green);
  background: var(--accent-green-bg);
}

/* MOBILE BOTTOM NAVIGATION BAR (HIDDEN ON DESKTOP) */
.mobile-bottom-nav {
  display: none;
}

/* LAYOUT CONTAINER */
.bakery-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  max-width: 1440px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  width: 100%;
  flex: 1;
}

.bakery-layout.dashboard-layout {
  grid-template-columns: 1fr 340px;
}

.workspace-left {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* CARDS & PANELS */
.bakery-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1.25rem;
}

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

.card-title-clean {
  font-size: 1rem;
  font-weight: 700;
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* DENSE STAT CARDS */
.stat-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.stat-box {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.stat-box.clickable-stat-box {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.stat-box.clickable-stat-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: #2B6CB0;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-val {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--brand-dark);
  margin: 0.2rem 0;
}

/* PASTEL BADGES */
.badge-pastel {
  font-size: 11px;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-critical { background: var(--accent-red-bg); color: var(--accent-red); }
.badge-medium { background: var(--accent-amber-bg); color: var(--accent-amber); }
.badge-low { background: var(--accent-blue-bg); color: var(--accent-blue-text); }
.badge-healthy { background: var(--accent-green-bg); color: var(--accent-green-text); }

/* DEVICE INVENTORY SCENARIO UI REDESIGN */
.device-table-card {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  margin-bottom: 2rem;
}

table.inventory-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

table.inventory-table th {
  background: #F8FAFC;
  color: #64748B;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  border-bottom: 1px solid #E2E8F0;
  white-space: nowrap;
}

table.inventory-table td {
  padding: 14px 16px;
  color: #334155;
  border-bottom: 1px solid #E2E8F0;
  vertical-align: middle;
  white-space: nowrap;
}

table.inventory-table tr:hover {
  background-color: #F8FAFC;
}

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

/* Category Badges (Pills) */
.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.pill-dolap {
  background-color: #E0F2FE;
  color: #0369A1;
  border: 1px solid #BAE6FD;
}

.pill-kompresor {
  background-color: #CCFBF1;
  color: #0F766E;
  border: 1px solid #99F6E4;
}

.pill-enerji {
  background-color: #FEF3C7;
  color: #B45309;
  border: 1px solid #FDE68A;
}

.pill-firin {
  background-color: #FFEDD5;
  color: #C2410C;
  border: 1px solid #FED7AA;
}

.pill-default {
  background-color: #F1F5F9;
  color: #475569;
  border: 1px solid #E2E8F0;
}

/* MODAL FIX & BEAUTIFICATION */
.modal-backdrop-clean {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.modal-dialog-clean {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  padding: 24px;
}

.modal-header-clean {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #F1F5F9;
}

.modal-title-clean {
  font-size: 16px;
  font-weight: 700;
  color: #0F172A;
}

.btn-close-clean {
  background: transparent;
  border: none;
  color: #94A3B8;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-close-clean:hover {
  color: #0F172A;
  background: #F1F5F9;
}

/* FORM ELEMENTS */
.form-group-clean {
  margin-bottom: 16px;
}

.form-label-clean {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #64748B;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.input-clean {
  width: 100%;
  height: 42px;
  padding: 10px 14px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  font-size: 14px;
  color: #0F172A;
  outline: none;
  transition: all 0.15s ease-in-out;
}

.input-clean:focus {
  border-color: #3B82F6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn-primary-solid {
  background: #0F172A;
  color: #FFFFFF;
  border: 1px solid #0F172A;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary-solid:hover {
  background: #1E293B;
  border-color: #1E293B;
}

.btn-outline-secondary {
  background: #FFFFFF;
  color: #334155;
  border: 1px solid #CBD5E1;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-outline-secondary:hover {
  background: #F8FAFC;
  border-color: #94A3B8;
  color: #0F172A;
}

.btn-text-link {
  background: transparent;
  color: #64748B;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s;
}

.btn-text-link:hover {
  color: #0F172A;
  text-decoration: underline;
}

/* DEVICE GRID CARDS */
.bakery-device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.bakery-device-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.2s;
}

.bakery-device-card:hover {
  border-color: var(--brand-blue);
}

.bakery-device-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--brand-dark);
}

/* CLEAN BAKERY TABLES */
table.bakery-table {
  width: 100%;
  border-collapse: collapse;
}

table.bakery-table th, table.bakery-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

table.bakery-table th {
  background: var(--bg-primary);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

/* FORMS & BUTTONS */
.btn-bakery {
  background: var(--brand-primary);
  color: #FFFFFF;
  border: none;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-bakery:hover { opacity: 0.92; }

.btn-bakery-secondary {
  background: var(--bg-primary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-bakery-secondary:hover {
  border-color: var(--border-hover);
}

.form-group-bakery {
  margin-bottom: 1.25rem;
}

.form-group-bakery label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.form-group-bakery input, .form-group-bakery select, .form-group-bakery textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group-bakery input:focus, .form-group-bakery select:focus {
  border-color: var(--brand-blue);
}

/* LIVE TIMELINE FEED (RIGHT PANEL) */
.timeline-feed {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.timeline-item {
  display: flex;
  gap: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.timeline-item:last-child {
  border-bottom: none;
}

.timeline-time {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.timeline-content {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.timeline-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-dark);
}

.timeline-desc {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
  white-space: normal;
}

/* Mobile status card list (Hidden on desktop) */
.mobile-card-list {
  display: none;
}

/* ==========================================================================
   BASE MODAL & CLEAN FORMS SYSTEM
   ========================================================================== */
.modal-backdrop-clean {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-dialog-clean {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  position: relative;
  animation: modalSlideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title-clean {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--brand-dark, #0f172a);
  margin: 0;
}

.btn-close-clean {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.btn-close-clean:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.form-group-clean {
  margin-bottom: 1rem;
}

.form-label-clean {
  display: block;
  font-size: 0.825rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.35rem;
}

.input-clean {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.875rem;
  color: #0f172a;
  background-color: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}

.input-clean:focus {
  outline: none;
  border-color: #0284c7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.btn-primary-solid {
  background: linear-gradient(135deg, #0284c7, #0d9488);
  color: #ffffff;
  border: none;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-primary-solid:hover {
  opacity: 0.92;
}

.btn-text-link {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
}

.btn-text-link:hover {
  color: #0f172a;
}

.btn-bakery, .btn-bakery-primary {
  background: linear-gradient(135deg, #2e7d32, #1b5e20);
  color: #ffffff !important;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 2px 4px rgba(46, 125, 50, 0.2);
  transition: all 0.15s ease;
}

.btn-bakery:hover, .btn-bakery-primary:hover {
  background: linear-gradient(135deg, #1b5e20, #0d3b11);
  box-shadow: 0 4px 8px rgba(46, 125, 50, 0.3);
  transform: translateY(-1px);
}

.btn-bakery-secondary {
  background: #F8F9FA;
  border: 1px solid var(--border-color, #DEE2E6);
  color: var(--text-main, #343A40);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-bakery-secondary:hover {
  background: #E9ECEF;
  border-color: #CED4DA;
}

/* ==========================================================================
   GLOBAL RESPONSIVE DESIGN (NATIVE MOBILE APP UX @ max-width: 768px)
   ========================================================================== */

@media (max-width: 768px) {
  body {
    padding-bottom: 70px; /* Leave space for bottom nav bar */
    font-size: 13px;
  }

  /* 1. Header & Navigation */
  .bakery-navbar {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .nav-links-clean {
    display: none; /* Hide desktop top nav links */
  }

  .branch-selector {
    font-size: 12px;
    padding: 0.35rem 0.6rem;
  }

  /* Fixed Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    z-index: 9999;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: #64748B;
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    flex: 1;
    padding: 6px 0;
  }

  .mobile-nav-item.active {
    color: #2e7d32;
    font-weight: 700;
  }

  .mobile-nav-icon {
    font-size: 18px;
    line-height: 1;
  }

  /* 2. Layout Grid */
  .bakery-layout {
    grid-template-columns: 1fr;
    padding: 0 1rem;
    margin: 1rem auto;
    gap: 1rem;
  }

  .stat-summary-grid {
    grid-template-columns: 1fr; /* 1 column on mobile */
    gap: 0.75rem;
  }

  .stat-box {
    padding: 0.85rem;
  }

  .stat-val {
    font-size: 1.5rem;
  }

  .bakery-card {
    padding: 1rem;
  }

  .bakery-device-grid {
    grid-template-columns: 1fr;
  }

  /* 3. Charts & Logs */
  .timeline-desc {
    word-break: break-word;
    white-space: normal;
  }

  /* 4. Tables & Status Cards */
  .desktop-table-only {
    display: none !important;
  }

  .mobile-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .mobile-status-card {
    background: #FFFFFF;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

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

  /* 5. Modals as Slide-up Bottom Sheets */
  .modal-backdrop-clean {
    padding: 0;
    align-items: flex-end;
  }

  .modal-dialog-clean {
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 20px 16px 28px 16px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease-out;
  }

  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .input-clean {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS auto-zoom on focus */
  }

  .btn-primary-solid, .btn-outline-secondary, .btn-bakery, .btn-bakery-secondary {
    min-height: 44px;
    box-sizing: border-box;
  }
}

/* PWA & Mobile Touch Ergonomics */
html, body {
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
  body {
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }

  .mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  }

  .table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
  }
}
