:root {
  --bg: #f4f5f7;
  --dark: #14171c;
  --border: #e2e4e9;
  --text: #1f2430;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --danger: #dc2626;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Topbar */
.topbar {
  background: var(--dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
}
.topbar h1 { font-size: 18px; font-weight: 600; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 14px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  background: #fff;
  color: var(--text);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f0f1f3; }
.btn-dark { background: #23262e; color: #fff; border-color: #23262e; }
.btn-dark:hover { background: #34383f; }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-icon { padding: 8px 12px; border-color: var(--border); font-size: 16px; }
.btn-block { width: 100%; }
.btn-menu {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
}

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #14171c, #2a2f3a);
}
.login-box {
  background: #fff;
  padding: 40px;
  border-radius: 12px;
  width: 320px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-box h1 { margin: 0 0 2px; font-size: 22px; }
.login-box .subtitle { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; }
.login-box label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-muted); }
.login-box input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.error-msg {
  background: #fee2e2;
  color: #991b1b;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* Toolbar */
.planner-main { padding: 20px 24px; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar select {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 14px;
  background: #fff;
}
.toolbar .spacer { flex: 1; }

/* Planner grid */
.planner-scroll { overflow-x: hidden; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.planner-grid {
  display: grid;
  grid-auto-rows: 64px;
  position: relative;
  width: 100%;
  grid-template-columns: var(--label-width, 240px) repeat(var(--days), minmax(var(--day-min, 0), 1fr)) var(--action-width, 56px);
}
.cell {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
}
.header-cell {
  background: #fafbfc;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  position: relative;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 8px 12px;
}
.label-header { position: sticky; left: 0; z-index: 3; background: #fafbfc; }
.week-header { text-align: left; }
.week-number { font-size: 14px; }
.week-range { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.action-header { border-right: none; }

.today-badge {
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translate(-50%, -100%);
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px 4px 0 0;
}

.row-label {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 2;
  gap: 10px;
}
.row-label .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.customer-name { font-weight: 600; font-size: 14px; }
.quantity { font-size: 12px; color: var(--text-muted); }

.row-actions { border-right: none; justify-content: center; }

.order-bar {
  align-self: center;
  height: 40px;
  margin: 0 4px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  user-select: none;
  z-index: 1;
  position: relative;
}
.order-bar.draggable { cursor: grab; }
.order-bar.dragging { cursor: grabbing; opacity: 0.85; z-index: 4; box-shadow: 0 6px 16px rgba(0,0,0,0.3); }
.order-bar.resizing { z-index: 4; box-shadow: 0 6px 16px rgba(0,0,0,0.3); }
.order-bar-label { pointer-events: none; overflow: hidden; text-overflow: ellipsis; }
.status-icon {
  pointer-events: none;
  flex-shrink: 0;
  margin-left: 6px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.status-icon-offen { background: rgba(255, 255, 255, 0.25); color: #fff; }
.status-icon-in_arbeit { background: rgba(255, 255, 255, 0.4); color: #fff; }
.status-icon-fertig { background: rgba(255, 255, 255, 0.9); color: #1b7a1b; }
.status-icon-geliefert { background: rgba(255, 255, 255, 0.9); color: #1b7a1b; }

.order-bar[data-status="geliefert"] { opacity: 0.6; }

.legend-status-icon { background: #e5e7eb; color: var(--text-muted); }

.resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
  z-index: 3;
}
.resize-handle.resize-left { left: 0; border-radius: 8px 0 0 8px; }
.resize-handle.resize-right { right: 0; border-radius: 0 8px 8px 0; }
.resize-handle:hover { background: rgba(255, 255, 255, 0.35); }

.today-line {
  pointer-events: none;
  display: flex;
  justify-content: center;
  z-index: 5;
}
.today-line-inner { width: 2px; background: #e53935; height: 100%; }

.day-gridline {
  pointer-events: none;
  z-index: 0;
  border-right: 1px solid rgba(20, 23, 28, 0.05);
}
.day-gridline-week-end { border-right-color: rgba(20, 23, 28, 0.1); }

.closure-band {
  pointer-events: none;
  z-index: 0;
  background: repeating-linear-gradient(
    135deg,
    rgba(20, 23, 28, 0.05) 0,
    rgba(20, 23, 28, 0.05) 10px,
    rgba(20, 23, 28, 0.09) 10px,
    rgba(20, 23, 28, 0.09) 20px
  );
  border-left: 1px solid rgba(20, 23, 28, 0.12);
  border-right: 1px solid rgba(20, 23, 28, 0.12);
}
.closure-label {
  display: inline-block;
  margin: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 8px);
}

/* Legend */
.legend {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; }
.closure-swatch {
  background: repeating-linear-gradient(
    135deg,
    rgba(20, 23, 28, 0.15) 0,
    rgba(20, 23, 28, 0.15) 3px,
    rgba(20, 23, 28, 0.3) 3px,
    rgba(20, 23, 28, 0.3) 6px
  );
}
.legend-hint { margin-left: auto; font-style: italic; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20,23,28,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal-box {
  background: #fff;
  padding: 28px;
  border-radius: 12px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-box h2 { margin: 0 0 18px; font-size: 18px; }
.modal-box label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-muted); }
.modal-box input, .modal-box select, .modal-box textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.modal-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* Dropdown menu (row actions) */
.dropdown-menu {
  position: absolute;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  z-index: 60;
  min-width: 140px;
  overflow: hidden;
}
.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  background: none;
  border: none;
  font-size: 13px;
  cursor: pointer;
}
.dropdown-menu button:hover { background: #f0f1f3; }
.dropdown-menu button.danger { color: var(--danger); }

/* Admin page */
.admin-main { padding: 24px; max-width: 900px; margin: 0 auto; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
.data-table th, .data-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-table th { background: #fafbfc; font-weight: 600; }
.color-swatch { width: 20px; height: 20px; border-radius: 5px; display: inline-block; }

.inline-form { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.inline-date-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.hint-text { color: var(--text-muted); font-size: 13px; margin: -4px 0 12px; }

.hidden { display: none !important; }

@media print {
  .topbar, .toolbar, .legend-hint, .row-actions, #order-modal { display: none !important; }
  body { background: #fff; }
  .planner-scroll { border: none; }
}

/* Mobile / Tablet */
@media (max-width: 900px) {
  .planner-main { padding: 14px; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; row-gap: 8px; }
  .topbar h1 { font-size: 16px; }
  .toolbar { gap: 8px; }
}

@media (max-width: 700px) {
  .planner-grid { --day-min: 26px; --label-width: 170px; --action-width: 40px; }
  .planner-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cell, .header-cell { padding: 0 8px; }
  .customer-name { font-size: 13px; }
  .quantity { font-size: 11px; }
  .btn { padding: 7px 10px; font-size: 13px; }
  .resize-handle { width: 16px; }
  .btn-menu { width: 36px; height: 36px; font-size: 18px; }
  .legend { gap: 12px; }
  .legend-hint { margin-left: 0; flex-basis: 100%; }
  .modal-box { padding: 20px; }
  .form-row { flex-direction: column; gap: 0; }
}
