/* ProdScheduler — Friendly White & Gray Production Workspace */
:root {
  color-scheme: light;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  background: var(--color-background);
  color: var(--color-foreground);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .kpi-value, .cal-date { font-family: var(--font-heading); }
.mono { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 248px;
  background: var(--color-card);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-xl) var(--space-lg);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-xs) var(--space-xs) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.logo-badge {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--color-primary), #6366F1);
  color: var(--color-on-primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
}

.logo-title { font-weight: 700; font-size: 15.5px; letter-spacing: -0.02em; color: var(--color-foreground); }
.logo-sub { font-size: 11.5px; color: var(--color-muted-foreground); font-weight: 500; }

.nav-list { display: flex; flex-direction: column; gap: 4px; margin-top: var(--space-lg); flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted-foreground);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 150ms ease, color 150ms ease;
}
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--color-muted); color: var(--color-foreground); }
.nav-item.active { background: var(--status-editing-bg); color: var(--color-primary); font-weight: 600; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

/* Main Area */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: var(--space-xl) var(--space-2xl) var(--space-3xl);
  gap: var(--space-xl);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  background: var(--color-card);
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar-left h1 { margin: 0; font-size: 18.5px; font-weight: 700; letter-spacing: -0.02em; }

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.sync-pill-local {
  background: var(--status-warn-bg);
  color: var(--status-warn-fg);
  border: 1px solid var(--status-warn-border);
}
.sync-pill-online {
  background: var(--status-done-bg);
  color: var(--status-done-fg);
  border: 1px solid var(--status-done-border);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.topbar-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.period-picker { display: flex; align-items: center; gap: 6px; }
.period-picker select {
  min-height: 36px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-muted);
  color: var(--color-foreground);
  font-weight: 600;
}

.mobile-only-btn { display: none !important; }

/* Buttons */
.btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}
.btn-sm { min-height: 32px; padding: 5px 11px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary {
  background: var(--color-card);
  border-color: var(--color-border);
  color: var(--color-foreground);
}
.btn-secondary:hover { background: var(--color-muted); border-color: var(--color-border-hover); }
.btn-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger-fg);
  border-color: var(--status-danger-border);
}
.btn-danger:hover { background: var(--status-danger-hover); }
.btn-ghost { background: transparent; color: var(--color-muted-foreground); }
.btn-ghost:hover { background: var(--color-muted); color: var(--color-foreground); }

.icon-btn {
  min-width: 36px;
  min-height: 36px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  cursor: pointer;
  color: var(--color-muted-foreground);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--color-muted); color: var(--color-foreground); }

/* KPI Strip */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-lg); }
.kpi-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 12px; color: var(--color-muted-foreground); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--color-foreground); }
.kpi-sub { font-size: 12px; color: var(--color-muted-foreground); margin-top: 3px; }

/* Card & Table */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-xl);
}
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.card-title { font-size: 15.5px; font-weight: 700; margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-md); align-items: center; }

.input, select {
  min-height: 36px;
  padding: 6px 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--color-card);
  color: var(--color-foreground);
  font-family: var(--font-body);
}
.input:focus, select:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}
th {
  background: var(--color-muted);
  color: var(--color-muted-foreground);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
tr:hover td { background: var(--color-background); }
tfoot td {
  background: var(--color-muted);
  font-weight: 700;
  border-top: 2px solid var(--color-border);
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.cell-btn:hover { background: var(--status-editing-bg); }

/* Calendar — Flat 1px Hairline Grid (Zero nested-cards) */
.calendar-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--color-muted-foreground); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-orange { background: var(--status-onset-dot); }
.dot-purple { background: var(--status-edit-dot); }
.dot-green { background: var(--status-done-dot); }
.dot-slate { background: var(--color-slate-dot); }

.cal-scroll { overflow-x: auto; padding-bottom: 6px; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--color-border);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.cal-head {
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-muted-foreground);
  padding: 9px 6px;
  background: var(--color-muted);
}
.cal-day {
  background: var(--color-card);
  min-height: 144px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cal-day.other-month { background: var(--color-background); opacity: 0.68; }
.cal-day.today {
  background: var(--color-today-bg);
}
.cal-day.today .cal-date {
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: 2px 8px;
  border-radius: 999px;
}
.cal-day-top { display: flex; align-items: center; justify-content: space-between; }
.cal-date { font-weight: 700; font-size: 12.5px; color: var(--color-foreground); }
.cal-add-btn {
  border: 1px solid var(--color-border);
  background: var(--color-muted);
  color: var(--color-muted-foreground);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.cal-add-btn:hover { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }

/* Slot Card */
.slot-card {
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  border-radius: 7px;
  padding: 7px 8px;
  font-size: 11.5px;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-muted);
  color: var(--color-foreground);
  transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}
.slot-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: var(--color-border-hover); }
.slot-card.type-onset { background: var(--status-onset-bg); border-color: var(--status-onset-border); }
.slot-card.type-edit { background: var(--status-edit-bg); border-color: var(--status-edit-border); }
.slot-card.status-done { background: var(--status-done-card-bg); border-color: var(--status-done-border); }

.slot-title { font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.slot-title-left { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.slot-meta { color: var(--color-muted-foreground); font-size: 11px; margin-top: 2px; white-space: normal; }
.slot-editors { margin-top: 4px; font-size: 10.5px; color: var(--color-foreground); white-space: normal; opacity: 0.85; }

/* Mobile Agenda & Cards */
.agenda-list, .mobile-task-cards { display: none; flex-direction: column; gap: 10px; }
.agenda-day {
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-card {
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: default;
}
.pill-clickable { cursor: pointer; }
.pill-done { background: var(--status-done-bg); color: var(--status-done-fg); border-color: var(--status-done-border); }
.pill-editing { background: var(--status-editing-bg); color: var(--status-editing-fg); border-color: var(--status-editing-border); }
.pill-planned { background: var(--color-muted); color: var(--color-muted-foreground); border-color: var(--color-border); }
.pill-overdue { background: var(--status-danger-bg); color: var(--status-danger-fg); border-color: var(--status-danger-border); }
.pill-soon { background: var(--status-warn-bg); color: var(--status-warn-fg); border-color: var(--status-warn-border); }

/* Slide-Over Detail Drawer & Confirm Dialog */
.drawer-backdrop, .confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(2px);
  display: flex;
  z-index: 100;
}
.drawer-backdrop { justify-content: flex-end; }
.confirm-backdrop { align-items: center; justify-content: center; padding: 16px; z-index: 150; }
.hidden { display: none !important; }

.drawer-panel {
  background: var(--color-card);
  border-left: 1px solid var(--color-border);
  width: 100%;
  max-width: 600px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: drawerSlideIn 180ms ease-out;
}
.confirm-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.confirm-card h3 { margin: 0 0 8px; font-size: 16px; }
.confirm-card p { margin: 0 0 18px; color: var(--color-muted-foreground); font-size: 13.5px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }

@keyframes drawerSlideIn {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xl);
  border-bottom: 1px solid var(--color-border);
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: var(--space-xl); overflow-y: auto; flex: 1; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-lg); }
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-muted-foreground);
}
.form-grid input, .form-grid select {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  background: var(--color-card);
  color: var(--color-foreground);
}
.col-span-2 { grid-column: span 2; }
.field-hint { font-size: 11.5px; color: var(--color-primary); min-height: 15px; }
.field-error { font-size: 11.5px; color: var(--status-danger-fg); margin-top: 4px; }

.editors-section { margin-top: var(--space-xl); padding-top: var(--space-xl); border-top: 1px solid var(--color-border); }
.editors-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-md); }
.editors-header h3 { margin: 0; font-size: 13.5px; }
.editor-rows { display: flex; flex-direction: column; gap: var(--space-md); }
.editor-row {
  display: grid;
  grid-template-columns: 1.4fr 0.65fr 1.2fr 1fr auto;
  gap: var(--space-md);
  align-items: center;
  background: var(--color-background);
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}
.editor-row input, .editor-row select { padding: 6px 8px; font-size: 12.5px; min-height: 36px; width: 100%; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-top: var(--space-2xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--color-border);
}
.modal-footer-right { display: flex; gap: var(--space-md); margin-left: auto; }

/* Config Grid */
.config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-xl); }
.tag-list { display: flex; flex-wrap: wrap; gap: var(--space-md); margin-top: var(--space-lg); }
.tag {
  background: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 12.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tag button {
  border: none;
  background: var(--color-card);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--color-muted-foreground);
  font-weight: 700;
}
.tag button:hover { background: var(--status-danger-bg); color: var(--status-danger-fg); }

/* QC Badge & Drive Submit */
.qc-badge {
  background: var(--color-destructive);
  color: var(--color-on-destructive);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}
.drive-submit-wrap { display: flex; gap: 6px; align-items: center; min-width: 240px; }
.drive-submit-wrap input { flex: 1; min-width: 140px; min-height: 34px; padding: 5px 8px; font-size: 12px; }
.drive-link-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
}
.drive-link-pill:hover { text-decoration: underline; }
.qc-list { display: flex; flex-direction: column; gap: var(--space-md); }
.qc-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-lg);
  background: var(--color-background);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.qc-item-info { display: flex; flex-direction: column; gap: 4px; }
.qc-item-actions { display: flex; flex-wrap: wrap; gap: var(--space-md); align-items: center; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--color-toast-bg);
  color: var(--color-toast-fg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

.mobile-nav { display: none; }

/* Tablet Breakpoint */
@media (max-width: 1080px) and (min-width: 901px) {
  .sidebar { width: 210px; }
  .main-area { padding: var(--space-lg); }
}

/* Mobile Breakpoint */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .mobile-only-btn { display: inline-flex !important; }
  .main-area { padding: 12px 12px 84px; gap: 12px; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi-card { padding: 11px 13px; }
  .kpi-value { font-size: 18px; margin-top: 2px; }
  .cal-scroll.show-grid-mobile .cal-grid { min-width: 920px; }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-card);
    border-top: 1px solid var(--color-border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 90;
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.05);
  }
  .mnav-item {
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: var(--color-muted-foreground);
    padding: 4px;
    cursor: pointer;
  }
  .mnav-item small { font-size: 10.5px; font-weight: 600; }
  .mnav-item.active { color: var(--color-primary); }

  .cal-scroll { display: none; }
  .cal-scroll.show-grid-mobile { display: block; }
  .agenda-list { display: flex; }
  .agenda-list.hide-agenda-mobile { display: none; }

  .deadline-table-wrap { display: none; }
  .mobile-task-cards { display: flex; }

  /* Accessible 44x44px touch targets on mobile */
  .btn-sm { min-height: 44px; padding: 8px 14px; }
  .pill-clickable { min-height: 44px; padding: 8px 14px; }
  .cal-add-btn { width: 44px; height: 44px; }
  .tag button { width: 44px; height: 44px; }

  .form-grid { grid-template-columns: 1fr; }
  .col-span-2 { grid-column: span 1; }
  .editor-row { grid-template-columns: 1fr 1fr; }
  .drawer-panel { max-width: 100%; }
  .toast { bottom: 76px; right: 12px; left: 12px; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer-panel { animation: none; }
  .slot-card, .btn, .nav-item {
    transition-property: color, background-color, border-color, opacity;
    transition-duration: 150ms;
  }
  .slot-card:hover { transform: none; }
}
