/* ================================================================
   PRODUCTIVITY — Factory-First Mobile UI
   Design: Bold, high-contrast, chunky touch targets
   Target: Factory floor workers on smartphones
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  /* === Colors === */
  --bg:             #e8edf8;
  --bg-2:           #f0f4fc;
  --panel:          #ffffff;
  --panel-soft:     #f5f8ff;
  --panel-tinted:   #eef4ff;

  --text:           #0f172a;
  --text-2:         #1e293b;
  --muted:          #475569;
  --muted-2:        #64748b;

  --border:         #cbd5e8;
  --border-strong:  #94a3c4;

  --primary:        #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft:   #eff6ff;
  --primary-tint:   #dbeafe;
  --primary-glow:   rgba(37, 99, 235, 0.18);

  --success:        #16a34a;
  --success-soft:   #f0fdf4;
  --success-tint:   #dcfce7;

  --danger:         #dc2626;
  --danger-soft:    #fef2f2;
  --danger-tint:    #fee2e2;

  --warning:        #d97706;
  --warning-soft:   #fffbeb;
  --warning-tint:   #fde68a;

  /* === Radius === */
  --radius-sm:   8px;
  --radius:      12px;
  --radius-lg:   16px;
  --radius-xl:   20px;
  --radius-full: 999px;

  /* === Shadows === */
  --shadow-sm:    0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:       0 4px 16px rgba(37, 99, 235, 0.06), 0 1px 4px rgba(15, 23, 42, 0.08);
  --shadow-card:  0 8px 24px rgba(37, 99, 235, 0.08), 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-float: 0 16px 40px rgba(37, 99, 235, 0.12), 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-btn:   0 4px 14px rgba(37, 99, 235, 0.28), 0 1px 4px rgba(37, 99, 235, 0.18);

  /* === Typography === */
  --font: "Plus Jakarta Sans", "Segoe UI", Arial, sans-serif;

  /* === Transitions === */
  --t:      200ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 130ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);

  /* === Safe areas === */
  --safe-top:    max(env(safe-area-inset-top), 0px);
  --safe-bottom: max(env(safe-area-inset-bottom), 16px);
  --safe-left:   env(safe-area-inset-left);
  --safe-right:  env(safe-area-inset-right);
}

/* ================================================================
   RESET & BASE
   ================================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
}

body.ns-body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(37, 99, 235, 0.1) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 85% 5%, rgba(22, 163, 74, 0.07) 0%, transparent 45%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
}

button, input, select, textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

/* ================================================================
   SHELL
   ================================================================ */

.ns-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 0 calc(80px + var(--safe-bottom));
}

/* ================================================================
   HEADER — Dark bar (nhà xưởng: giảm chói mắt, nổi bật thương hiệu)
   ================================================================ */

.ns-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border-bottom: 1px solid rgba(203, 213, 232, 0.6);
  box-shadow:
    0 4px 20px rgba(15, 23, 42, 0.05),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.ns-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: calc(10px + var(--safe-top));
  padding-bottom: 10px;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  border: none;
  border-radius: 0;
  background: transparent;
}

.ns-brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  flex: 1 1 auto;
}

.ns-brand__logo {
  display: block;
  width: auto;
  height: 30px;
  max-width: min(160px, 44vw);
  object-fit: contain;
  /* Logo trên nền sáng — giữ nguyên bản màu xanh dương */
  opacity: 1;
}

.ns-topbar__actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

/* ================================================================
   BUTTONS — Base system
   ================================================================ */

.ns-ghost-button,
.ns-primary-button,
.ns-danger-button,
.ns-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  font-size: 0.97rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    transform var(--t-fast),
    border-color var(--t-fast),
    background var(--t-fast),
    color var(--t-fast),
    box-shadow var(--t-fast);
}

/* Ghost */
.ns-ghost-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Primary */
.ns-primary-button {
  border-color: var(--primary-strong);
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #ffffff;
  box-shadow: var(--shadow-btn);
}

.ns-primary-button:hover {
  filter: brightness(1.06);
  box-shadow: var(--shadow-float);
}

/* Danger */
.ns-danger-button {
  border-color: #b91c1c;
  background: linear-gradient(145deg, var(--danger) 0%, #b91c1c 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.28);
}

.ns-danger-button:hover {
  filter: brightness(1.06);
}

/* Active press feedback */
.ns-ghost-button:active,
.ns-primary-button:active,
.ns-danger-button:active,
.ns-icon-button:active {
  transform: scale(0.97);
}

/* ================================================================
   ICON BUTTON — 48×48 minimum touch target
   ================================================================ */

.ns-icon-button {
  min-width: 48px;
  width: 48px;
  min-height: 48px;
  height: 48px;
  padding: 0;
  border-radius: var(--radius-sm);
  border-color: var(--border-strong);
  background: var(--panel);
  color: var(--muted);
}

.ns-icon-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.ns-icon-button svg {
  display: block;
  width: 22px;
  height: 22px;
}

/* ================================================================
   STATUS ICON — Online / Offline indicator
   ================================================================ */

.ns-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(22, 163, 74, 0.25);
  background: var(--success-soft);
  color: var(--success);
}

.ns-status-icon svg {
  display: block;
  width: 22px;
  height: 22px;
}

.ns-status-icon.is-api-down,
.ns-status-icon.is-offline {
  border-color: rgba(220, 38, 38, 0.25);
  background: var(--danger-soft);
  color: var(--danger);
}

/* ================================================================
   TOAST
   ================================================================ */

.ns-toast-host {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 2100;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 28px));
  pointer-events: none;
}

.ns-toast {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: var(--shadow-float);
  pointer-events: auto;
  animation: toast-in 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ns-toast--success {
  color: var(--success);
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  border: 1px solid #bbf7d0;
}

.ns-toast--error {
  color: var(--danger);
  background: linear-gradient(135deg, #fef2f2, #fee2e2);
  border: 1px solid #fecaca;
}

.ns-toast--warning {
  color: var(--warning);
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1px solid #fde68a;
}

.ns-toast--info {
  color: var(--primary);
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border: 1px solid #bfdbfe;
}

/* ================================================================
   MAIN LAYOUT
   ================================================================ */

.ns-main {
  display: grid;
  gap: 16px;
  padding: 16px max(16px, var(--safe-left)) 0 max(16px, var(--safe-right));
}

/* ================================================================
   CARDS
   ================================================================ */

.ns-card,
.ns-alert {
  background: var(--panel);
  border: 1px solid rgba(203, 213, 232, 0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.ns-card {
  --card-padding: 20px;
  padding: 20px;
}

.ns-card__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.ns-card__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}

.ns-card__subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ================================================================
   PAGE INTRO
   ================================================================ */

.ns-page-intro {
  display: grid;
  gap: 6px;
  padding-inline: 4px;
}

.ns-page-intro__title {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
  line-height: 1.2;
}

.ns-page-intro__subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.97rem;
  line-height: 1.55;
}

/* ================================================================
   SECTIONS & GRIDS
   ================================================================ */

.ns-page-section,
.ns-section-grid,
.ns-history-list,
.ns-queue-list {
  display: grid;
  gap: 14px;
}

.ns-form-grid,
.ns-filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

/* ================================================================
   FORM FIELDS
   ================================================================ */

.ns-field {
  display: grid;
  gap: 8px;
}

.ns-field span,
.ns-field > label span {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.01em;
}

.ns-field--wide,
.ns-form-actions,
.ns-timeslot-panel {
  grid-column: 1 / -1;
}

/* Form controls inside ns-form-grid */
.ns-form-grid .form-control,
.ns-form-grid .form-select,
.ns-filter-grid .form-control,
.ns-filter-grid .form-select,
.ns-device-card .form-control {
  min-height: 54px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  font-size: 1rem;
  font-weight: 600;
  padding-inline: 14px;
  background: #ffffff;
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  -webkit-appearance: none;
}

.ns-form-grid .form-control:focus,
.ns-form-grid .form-select:focus,
.ns-filter-grid .form-control:focus,
.ns-filter-grid .form-select:focus,
.ns-device-card .form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ================================================================
   FORM ACTIONS
   ================================================================ */

.ns-form-actions,
.ns-filter-actions,
.ns-modal-actions,
.ns-history-item__actions,
.ns-sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ns-form-actions {
  justify-content: stretch;
}

.ns-filter-actions {
  align-items: stretch;
}

.ns-form-actions > button,
.ns-filter-actions > button,
.ns-modal-actions > button,
.ns-sync-actions > button {
  flex: 1 1 180px;
}

.ns-filter-actions > button {
  flex: 1 1 0;
  min-width: 0;
}

/* ================================================================
   NUMBER INPUT
   ================================================================ */

.ns-number-input {
  text-align: center;
  font-weight: 800;
  font-size: 1.15rem !important;
}

/* ================================================================
   PICKER SELECT (hidden native)
   ================================================================ */

.ns-picker-select[hidden] {
  display: none !important;
}

/* ================================================================
   PICKER BUTTON — big tap target
   ================================================================ */

.ns-picker-button {
  min-height: 54px;
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #ffffff 0%, #f8faff 100%);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}

.ns-picker-button:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.ns-picker-button:active {
  transform: scale(0.99);
}

/* ================================================================
   REPORT FORM GRID
   ================================================================ */

.ns-form-grid--report {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ns-form-grid--report .ns-plan-summary {
  grid-column: 1 / -1;
}

/* ================================================================
   DATE INPUT
   ================================================================ */

.ns-date-input {
  position: relative;
  display: block;
}

.ns-date-display {
  text-align: left;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding-right: 54px !important;
}

.ns-date-trigger {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  min-width: 52px;
  min-height: auto;
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  transition: color var(--t-fast);
}

.ns-date-trigger:hover {
  color: var(--primary-strong);
}

.ns-date-trigger:active {
  transform: scale(0.95);
}

.ns-date-actual {
  position: absolute;
  inset: auto;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ================================================================
   PLAN SUMMARY
   ================================================================ */

.ns-plan-summary {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel-tinted);
  border: 1.5px dashed var(--border-strong);
}

.ns-plan-summary.is-empty {
  color: var(--muted);
}

.ns-plan-summary__title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.ns-plan-summary__status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.ns-plan-summary__grid {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.93rem;
}

.ns-plan-summary__notice {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid #fbbf24;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  color: #92400e;
  font-size: 0.9rem;
  font-weight: 700;
}

.ns-plan-expiry {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

/* ================================================================
   PICKER — Filter chips
   ================================================================ */

.ns-picker-filter-strip {
  margin-bottom: 16px;
}

.ns-picker-search {
  margin-bottom: 14px;
}

.ns-picker-filter-scroll {
  overflow-x: auto;
  padding-bottom: 8px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.ns-picker-filter-scroll::-webkit-scrollbar {
  display: none;
}

.ns-picker-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.ns-filter-chip {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 8px 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: #fff;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.ns-filter-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.ns-filter-chip.is-active {
  border-color: var(--primary);
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.ns-line-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ns-line-chip {
  min-height: 46px;
}

.ns-line-chip.is-locked,
.ns-line-chip:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.ns-line-chip.is-locked:not(.is-active):disabled {
  border-color: var(--border);
  background: var(--panel-soft);
  color: var(--muted-2);
  box-shadow: none;
}

/* ================================================================
   PICKER MODAL GRID
   ================================================================ */

.ns-picker-modal-grid-area {
  min-height: 220px;
}

.ns-picker-modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* ================================================================
   PICKER CARDS — 64px touch-friendly
   ================================================================ */

.ns-picker-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  padding: 14px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff 0%, #f5f8ff 100%);
  text-align: center;
  cursor: pointer;
  transition: all var(--t-fast);
}

.ns-picker-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-card);
  transform: translateY(-2px);
}

.ns-picker-card.is-active {
  border-color: var(--primary);
  background: linear-gradient(145deg, var(--primary-soft) 0%, var(--primary-tint) 100%);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.ns-picker-card__code {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  word-break: break-word;
  line-height: 1.3;
}

.ns-picker-card.is-active .ns-picker-card__code {
  color: var(--primary-strong);
}

/* ================================================================
   TIMESLOT PANEL
   ================================================================ */

.ns-timeslot-panel {
  margin-inline: calc(-1 * var(--card-padding));
  width: calc(100% + var(--card-padding) * 2);
  padding: 0;
  border-radius: 0;
  background: linear-gradient(180deg, var(--primary-soft) 0%, var(--primary-tint) 100%);
  border: 1px solid #bfdbfe;
  border-left: none;
  border-right: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  overflow: hidden;
}

.ns-timeslot-panel__header {
  display: flex;
  width: 100%;
  margin-bottom: 0;
}

.ns-timeslot-hint {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.ns-timeslot-total {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1.5px solid #bfdbfe;
  background: rgba(37, 99, 235, 0.06);
}

.ns-timeslot-total__label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary-strong);
}

.ns-timeslot-total strong {
  display: block;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary);
}

.ns-timeslot-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: transparent;
}

.ns-timeslot-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(191, 219, 254, 0.5);
  background: transparent;
  transition: background var(--t-fast);
}

.ns-timeslot-item:last-child {
  border-bottom: none;
}

.ns-timeslot-item:hover {
  background: rgba(255, 255, 255, 0.5);
}

.ns-timeslot-item__label {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-2);
}

.ns-timeslot-item .form-control {
  height: 42px;
  width: 100%;
  padding: 6px 12px;
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
  border-radius: var(--radius-sm);
  border-color: #93c5fd;
  background: rgba(255, 255, 255, 0.85);
}

.ns-timeslot-item .form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: #ffffff;
}

/* ================================================================
   HISTORY ITEMS
   ================================================================ */

.ns-history-item,
.ns-queue-item {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-soft);
  transition: box-shadow var(--t);
}

.ns-history-item__header,
.ns-queue-item__header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.ns-history-item__meta,
.ns-history-item__stats,
.ns-queue-item__meta,
.ns-current-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ns-history-item__meta div,
.ns-history-item__stats div,
.ns-queue-item__meta div,
.ns-current-card dl div {
  display: grid;
  gap: 4px;
}

.ns-history-item__meta dt,
.ns-history-item__stats dt,
.ns-queue-item__meta dt,
.ns-current-card dt {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.ns-history-item__meta dd,
.ns-history-item__stats dd,
.ns-queue-item__meta dd,
.ns-current-card dd {
  margin: 0;
  font-weight: 700;
  font-size: 0.97rem;
}

.ns-history-item__headline {
  min-width: 0;
}

.ns-history-item__headline strong {
  display: block;
  font-size: 1rem;
  font-weight: 800;
}

.ns-history-item__actions {
  margin-left: auto;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

/* ================================================================
   ICON ACTION BUTTONS — inside cards
   ================================================================ */

.ns-icon-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--panel);
  color: var(--primary);
  cursor: pointer;
  transition: all var(--t-fast);
}

.ns-icon-action-button:active {
  transform: scale(0.94);
}

.ns-icon-action-button.is-danger {
  border-color: #fca5a5;
  background: var(--danger-soft);
  color: var(--danger);
}

.ns-icon-action-button.is-warning {
  border-color: #fcd34d;
  background: var(--warning-soft);
  color: #b45309;
}

.ns-icon-action-button.is-success {
  border-color: #86efac;
  background: #f0fdf4;
  color: #15803d;
}

.ns-history-item__total {
  grid-column: 1 / -1;
  justify-items: center;
  padding-top: 2px;
  text-align: center;
}

.ns-history-item__total dd {
  color: var(--primary);
  font-size: 1.1rem;
  font-weight: 800;
}

/* ================================================================
   CURRENT CARD
   ================================================================ */

.ns-current-card dl {
  margin: 0;
}

.ns-current-card dl > div:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

/* ================================================================
   ALERTS
   ================================================================ */

.ns-alert {
  padding: 16px 18px;
  font-weight: 700;
  font-size: 0.97rem;
}

.ns-alert--warning {
  border-color: #fcd34d;
  background: linear-gradient(135deg, var(--warning-soft), #fef3c7);
  color: #92400e;
}

.ns-alert--info {
  border-color: #93c5fd;
  background: linear-gradient(135deg, var(--primary-soft), var(--primary-tint));
  color: var(--primary-strong);
}

/* ================================================================
   SYNC REFRESH BANNER
   ================================================================ */

.ns-sync-refresh {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ns-sync-refresh__copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ns-sync-refresh__copy strong {
  font-size: 0.97rem;
}

.ns-sync-refresh__copy span {
  color: var(--primary-strong);
  font-size: 0.92rem;
  line-height: 1.45;
}

/* ================================================================
   EMPTY STATE
   ================================================================ */

.ns-empty-state {
  padding: 24px;
  border-radius: var(--radius);
  border: 1.5px dashed var(--border-strong);
  color: var(--muted);
  background: var(--panel-soft);
  text-align: center;
  font-size: 0.95rem;
}

/* ================================================================
   SYNC MODAL
   ================================================================ */

.ns-sync-modal-body {
  display: grid;
  gap: 18px;
}

.ns-sync-rows {
  display: grid;
  gap: 10px;
}

.ns-sync-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--panel-soft);
  border: 1px solid var(--border);
}

.ns-sync-row--device {
  align-items: flex-start;
}

.ns-sync-row__label {
  font-size: 0.93rem;
  font-weight: 700;
  color: var(--muted);
}

.ns-sync-row__value {
  font-size: 1rem;
  font-weight: 700;
}

.ns-sync-device-meta {
  display: grid;
  justify-items: end;
  gap: 6px;
  text-align: right;
}

.ns-sync-device-text {
  color: var(--muted);
  font-size: 0.92rem;
}

.ns-sync-section {
  display: grid;
  gap: 10px;
}

.ns-sync-section__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.ns-sync-errors {
  min-height: 88px;
  padding: 14px;
  border-radius: var(--radius);
  background: #0f172a;
  color: #94a3b8;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-line;
  font-family: "JetBrains Mono", "Consolas", monospace;
}

/* ================================================================
   QUEUE
   ================================================================ */

.ns-queue-summary {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  font-weight: 700;
}

.ns-queue-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.ns-queue-chip--create {
  background: var(--primary-tint);
  color: #1e40af;
}

.ns-queue-chip--update {
  background: var(--warning-tint);
  color: #92400e;
}

.ns-queue-chip--delete {
  background: var(--danger-tint);
  color: #991b1b;
}

.ns-queue-item.is-pending-create {
  border-color: #93c5fd;
  border-left: 3px solid var(--primary);
}

.ns-queue-item.is-pending-update {
  border-color: #fcd34d;
  border-left: 3px solid var(--warning);
}

.ns-queue-item.is-pending-delete {
  border-color: #fca5a5;
  border-left: 3px solid var(--danger);
}

/* ================================================================
   STATUS BADGE
   ================================================================ */

.ns-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-full);
  background: var(--warning-soft);
  border: 1px solid var(--warning-tint);
  color: #92400e;
  font-weight: 800;
  font-size: 0.9rem;
}

.ns-status-badge.is-approved {
  background: var(--success-soft);
  border-color: var(--success-tint);
  color: var(--success);
}

/* ================================================================
   MODAL OVERRIDES
   ================================================================ */

.ns-modal-note {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.97rem;
}

.modal-content {
  border-radius: var(--radius-lg) !important;
  border: 1px solid rgba(203, 213, 232, 0.6) !important;
  box-shadow: var(--shadow-float) !important;
}

.modal-header {
  border-bottom-color: var(--border) !important;
}

.modal-footer {
  border-top-color: var(--border) !important;
}

#syncStatusModal .modal-header,
#deviceSettingsModal .modal-header,
#confirmModal .modal-header {
  justify-content: flex-end;
  padding-bottom: 0;
  border-bottom: 0 !important;
}

/* ================================================================
   DEVICE SETTINGS
   ================================================================ */

.ns-device-panel {
  display: grid;
  gap: 16px;
}

.ns-device-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.ns-device-card--qr {
  gap: 18px;
}

.ns-device-camera-column,
.ns-device-control-column {
  display: grid;
  gap: 12px;
}

.ns-device-control-column .ns-modal-actions {
  flex-wrap: wrap;
}

.ns-qr-scanner-video {
  width: 100%;
  min-height: 220px;
  border-radius: var(--radius);
  background: #0f172a;
  object-fit: cover;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.ns-qr-scanner-status {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.06);
  color: var(--muted);
  font-size: 0.93rem;
}

.ns-modal-result {
  min-height: 24px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.ns-modal-result.is-error {
  color: var(--danger);
}

/* ================================================================
   BOTTOM NAVIGATION — 72px, icon 24px
   ================================================================ */

.ns-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  padding: 0 0 var(--safe-bottom);
  border: none;
  border-top: 1px solid rgba(203, 213, 232, 0.7);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -6px 24px rgba(37, 99, 235, 0.08), 0 -1px 4px rgba(15, 23, 42, 0.05);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
}

.ns-bottom-nav__item {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 5px;
  min-height: 72px;
  padding: 10px 6px;
  border-radius: 0;
  color: var(--muted-2);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: color var(--t-fast), transform var(--t-fast);
  position: relative;
}

.ns-bottom-nav__item svg {
  display: block;
  width: 24px;
  height: 24px;
  transition: transform var(--t-fast);
}

/* Active indicator: pill above icon */
.ns-bottom-nav__item::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 32px;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--primary);
  transition: transform var(--t);
}

.ns-bottom-nav__item.is-active {
  color: var(--primary);
}

.ns-bottom-nav__item.is-active::before {
  transform: translateX(-50%) scaleX(1);
}

.ns-bottom-nav__item.is-active svg {
  transform: translateY(-1px);
}

.ns-bottom-nav__item:active {
  color: var(--primary);
  transform: scale(0.92);
}

/* ================================================================
   COLLAPSIBLE HISTORY ITEMS
   ================================================================ */

.ns-history-item.is-collapsible {
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow var(--t), border-color var(--t);
  border: 1px solid var(--border);
  background: var(--panel);
}

.ns-history-item.is-collapsible:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-card);
}

.ns-history-item__summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  background: var(--panel);
  user-select: none;
  gap: 14px;
}

.ns-history-item__summary-left {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 5px;
  min-width: 0;
}

.ns-history-item__summary-code {
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ns-history-item__summary-date {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}

.ns-history-item__summary-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ================================================================
   PLAN BADGE — pill style
   ================================================================ */

.ns-plan-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.ns-plan-badge.is-open {
  background: var(--success-tint);
  color: #15803d;
  border: 1px solid #86efac;
}

.ns-plan-badge.is-warning {
  background: var(--warning-tint);
  color: #92400e;
  border: 1px solid #fcd34d;
}

.ns-plan-badge.is-overdue {
  background: var(--danger-tint);
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.ns-plan-badge.is-closed {
  background: var(--panel-soft);
  color: var(--muted);
  border: 1px solid var(--border);
}

.ns-plan-badge.is-neutral {
  background: var(--panel-soft);
  color: var(--text-2);
  border: 1px solid var(--border);
}

/* ================================================================
   CHEVRON — expand/collapse
   ================================================================ */

.ns-history-item__chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  transition: transform var(--t), background var(--t), color var(--t), border-color var(--t);
  flex-shrink: 0;
}

.ns-history-item.is-collapsible:hover .ns-history-item__chevron {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-tint);
}

.ns-history-item.is-expanded .ns-history-item__chevron {
  transform: rotate(180deg);
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary-strong);
}

/* ================================================================
   HISTORY ITEM DETAILS (collapsed/expanded)
   ================================================================ */

.ns-history-item__details {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition:
    max-height var(--t-slow),
    opacity var(--t),
    padding var(--t-slow);
  padding-inline: 20px;
  background: var(--panel-soft);
  border-top: 1px solid transparent;
}

.ns-history-item.is-expanded .ns-history-item__details {
  max-height: 800px;
  opacity: 1;
  padding-top: 18px;
  padding-bottom: 18px;
  border-top-color: var(--border);
}

.ns-history-item__details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.ns-history-item__details-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ns-history-item__details-row--full {
  grid-column: 1 / -1;
}

.ns-history-item__details-label {
  font-size: 0.83rem;
  color: var(--muted);
  font-weight: 600;
}

.ns-history-item__details-value {
  font-size: 0.97rem;
  font-weight: 700;
  color: var(--text);
}

.ns-history-item__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px dashed var(--border-strong);
  padding-top: 14px;
}

.ns-history-item__actions .ns-icon-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 42px;
  padding: 0 10px;
  width: auto;
  min-width: 40px;
  font-size: 0.82rem;
  font-weight: 700;
  transition: all var(--t-fast);
  border-radius: var(--radius-sm);
}

.ns-history-item__actions .ns-icon-action-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.ns-history-item__actions .ns-icon-action-button.is-danger:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.ns-history-item__actions .ns-icon-action-button.is-warning:hover {
  border-color: #d97706;
  background: var(--warning-soft);
  color: #92400e;
}

.ns-history-item__actions .ns-icon-action-button.is-success:hover {
  border-color: #16a34a;
  background: #f0fdf4;
  color: #15803d;
}

/* ================================================================
   REPORT DETAIL MODAL
   ================================================================ */

.ns-report-detail-grid {
  display: grid;
  gap: 12px 16px;
}

.ns-report-detail-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
}

.ns-report-detail-label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--muted);
}

.ns-report-detail-value {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}

.ns-report-detail-section {
  margin-top: 20px;
}

.ns-report-detail-section__title {
  margin: 0 0 12px;
  font-size: 0.97rem;
  font-weight: 800;
  color: var(--text);
}

.ns-report-detail-timeslots {
  display: grid;
  gap: 8px;
}

.ns-report-detail-timeslot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.ns-report-detail-timeslot__name {
  font-size: 0.93rem;
  color: var(--text);
  font-weight: 600;
}

.ns-report-detail-timeslot__value {
  font-size: 1rem;
  font-weight: 800;
  color: var(--primary);
}

/* ================================================================
   PAGINATION
   ================================================================ */

.ns-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
  padding: 14px 0 6px 0;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.ns-pagination__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  font-size: 0.93rem;
  font-weight: 700;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: all var(--t-fast);
  user-select: none;
}

.ns-pagination__btn:hover:not(:disabled) {
  border-color: var(--primary);
  background-color: var(--primary-soft);
  color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.ns-pagination__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--border);
}

.ns-pagination__btn.is-active {
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-strong) 100%);
  border-color: var(--primary-strong);
  color: #ffffff;
  box-shadow: var(--shadow-btn);
}

.ns-pagination__info {
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 6px;
}

/* ================================================================
   SEARCHABLE SELECT
   ================================================================ */

.ns-searchable-select-wrapper {
  position: relative;
  width: 100%;
}

.ns-searchable-select-input {
  cursor: text;
  padding-right: 40px;
}

.ns-searchable-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1050;
  display: none;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 6px;
  padding: 6px;
  background-color: var(--panel);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
}

.ns-searchable-select-dropdown.show {
  display: block;
  animation: dropdown-in 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ns-searchable-select-dropdown .dropdown-item {
  width: 100%;
  padding: 12px 14px;
  clear: both;
  font-weight: 600;
  color: var(--text);
  text-align: inherit;
  white-space: nowrap;
  background-color: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.97rem;
  transition: background-color var(--t-fast), color var(--t-fast);
}

.ns-searchable-select-dropdown .dropdown-item:hover,
.ns-searchable-select-dropdown .dropdown-item:focus {
  background-color: var(--panel-soft);
  color: var(--primary);
  outline: none;
}

.ns-searchable-select-dropdown .dropdown-item.active,
.ns-searchable-select-dropdown .dropdown-item:active {
  background-color: var(--primary-soft);
  color: var(--primary-strong);
}

.ns-searchable-select-dropdown .dropdown-item.disabled {
  pointer-events: none;
  background-color: transparent;
  color: var(--muted);
  opacity: 0.6;
}

/* ================================================================
   UTILITIES
   ================================================================ */

.is-hidden {
  display: none !important;
}

.ns-filter-grid + .ns-history-list {
  margin-top: 12px;
}

/* ================================================================
   RESPONSIVE — Mobile first, expand up
   ================================================================ */

/* Small mobile: stack everything */
@media (max-width: 679px) {
  .ns-card {
    --card-padding: 16px;
    padding: 16px;
  }

  .ns-main {
    gap: 14px;
    padding-inline: 14px;
  }

  .ns-history-item__meta,
  .ns-queue-item__meta {
    grid-template-columns: 1fr;
  }

  .ns-sync-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .ns-sync-device-meta {
    width: 100%;
    justify-items: start;
    text-align: left;
  }

  .ns-form-grid--report {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ns-timeslot-item,
  .ns-timeslot-total {
    grid-template-columns: minmax(0, 1fr) 88px;
    gap: 10px;
  }

  .ns-timeslot-total strong {
    font-size: 1.15rem;
  }
}

/* Tablet: 2-col section grid */
@media (min-width: 680px) {
  .ns-shell {
    padding-inline: 0;
  }

  .ns-main {
    padding-inline: 20px;
    gap: 18px;
  }

  .ns-section-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ns-form-grid,
  .ns-filter-grid,
  .ns-device-card--qr,
  .ns-queue-item__header {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ns-form-actions {
    justify-content: flex-end;
  }

  .ns-form-actions > button,
  .ns-filter-actions > button,
  .ns-modal-actions > button,
  .ns-sync-actions > button {
    flex: 0 0 auto;
  }

  .ns-report-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ns-sync-row {
    align-items: center;
  }

  .ns-sync-device-meta {
    justify-items: end;
  }

  .ns-picker-modal-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Desktop: asymmetric 2-col */
@media (min-width: 960px) {
  .ns-main {
    max-width: 1200px;
    margin-inline: auto;
    padding-inline: 32px;
  }

  .ns-section-grid {
    grid-template-columns: 1.15fr 0.85fr;
    align-items: start;
  }

  .ns-picker-modal-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
