:root {
  --bg: #eef1ef;
  --surface: #ffffff;
  --surface-soft: #f6f8f7;
  --ink: #18201d;
  --muted: #75807b;
  --line: #dfe5e1;
  --line-strong: #cfd7d2;
  --green: #0f766e;
  --green-dark: #0b5752;
  --green-soft: #d9efeb;
  --amber: #d78c24;
  --amber-soft: #f8ead1;
  --blue: #3e76a7;
  --blue-soft: #ddebf5;
  --red: #c64e47;
  --red-soft: #f7e3e1;
  --purple: #7667a8;
  --purple-soft: #ebe7f5;
  --header-h: 72px;
  --hour-h: 34px;
  font-family: "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }

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

.topbar {
  height: var(--header-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 28px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 17px; line-height: 1.15; font-weight: 700; }
.brand p { margin: 5px 0 0; color: var(--muted); font: 500 10px/1 "DM Mono", monospace; letter-spacing: .08em; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 7px; background: var(--ink);
  display: flex; align-items: flex-end; justify-content: center; gap: 3px; padding: 8px;
}
.brand-mark span { width: 4px; background: #68c2b7; border-radius: 2px 2px 0 0; }
.brand-mark span:nth-child(1) { height: 9px; }
.brand-mark span:nth-child(2) { height: 17px; background: #f2c36b; }
.brand-mark span:nth-child(3) { height: 13px; }

.live-clock { display: flex; align-items: center; gap: 10px; }
.live-clock div { display: flex; align-items: baseline; gap: 12px; }
.live-clock strong { font: 500 20px/1 "DM Mono", monospace; font-variant-numeric: tabular-nums; }
.live-clock span:last-child { font-size: 12px; color: var(--muted); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #1aa66f; box-shadow: 0 0 0 4px #dff3e9; animation: pulse 2s infinite; }

.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.icon-button, .primary-button, .secondary-button, .danger-button, .filter-button, .today-button, .week-label, .text-button {
  border: 0; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-button {
  width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface);
  transition: background .2s, border-color .2s, transform .2s;
}
.icon-button:hover { background: var(--surface-soft); border-color: var(--line-strong); }
.icon-button:active { transform: scale(.96); }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.compact { width: 30px; height: 30px; }
.icon-button.compact svg { width: 15px; height: 15px; }
.primary-button {
  gap: 8px; min-height: 38px; padding: 0 15px; border-radius: 7px; background: var(--ink); color: white; font-size: 13px; font-weight: 600;
  transition: background .2s, transform .2s;
}
.primary-button:hover { background: #2b3733; }
.primary-button:active { transform: translateY(1px); }
.primary-button svg { width: 16px; height: 16px; }
.avatar { width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); font: 600 12px/1 "DM Mono", monospace; cursor: pointer; }
.mobile-booking-button { display: none; }

.overview {
  height: 132px;
  padding: 22px 28px;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.overview-heading { align-self: center; }
.eyebrow { display: block; color: var(--green); font: 500 9px/1 "DM Mono", monospace; letter-spacing: .1em; text-transform: uppercase; }
.overview-heading h2 { margin: 7px 0 5px; font-size: 22px; line-height: 1.2; }
.overview-heading p { margin: 0; color: var(--muted); font-size: 11px; }
.metric-strip { display: grid; grid-template-columns: repeat(4, 1fr); border-left: 1px solid var(--line); }
.metric { padding: 4px 24px; border-right: 1px solid var(--line); display: flex; flex-direction: column; justify-content: center; }
.metric.last { border-right: 0; }
.metric > span { color: var(--muted); font-size: 11px; }
.metric strong { margin: 5px 0 8px; font: 500 27px/1 "DM Mono", monospace; }
.metric strong small { color: var(--muted); font-size: 12px; margin-left: 4px; }
.metric-bar { height: 3px; max-width: 110px; background: #e8ecea; border-radius: 3px; overflow: hidden; }
.metric-bar span { display: block; height: 100%; background: #3a6d59; transition: width .5s; }
.metric-bar.amber span { background: var(--amber); }
.metric-bar.teal span { background: var(--green); }
.metric-caption { display: flex; gap: 4px; align-items: center; color: var(--green); font-size: 10px; }
.metric-caption svg { width: 12px; height: 12px; }

.workspace { display: grid; grid-template-columns: minmax(800px, 1fr) 310px; min-height: calc(100vh - 204px); }
.schedule-panel { min-width: 0; position: relative; border-right: 1px solid var(--line); background: var(--surface); }
.schedule-toolbar {
  height: 58px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.week-navigator, .toolbar-controls, .legend { display: flex; align-items: center; }
.week-navigator { gap: 6px; }
.toolbar-controls { gap: 20px; }
.week-label { height: 32px; gap: 8px; padding: 0 9px; background: transparent; border-radius: 6px; font-size: 13px; font-weight: 600; }
.week-label:hover { background: var(--surface-soft); }
.week-label svg { width: 14px; height: 14px; color: var(--muted); }
.today-button { height: 30px; margin-left: 5px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: white; font-size: 11px; }
.legend { gap: 13px; color: var(--muted); font-size: 10px; }
.legend > span { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-dot { width: 7px; height: 7px; border-radius: 2px; background: var(--green); }
.legend-dot.booked { background: var(--blue); }
.legend-dot.maintenance { background: var(--purple); }
.filter-button { height: 32px; gap: 7px; padding: 0 10px; border: 1px solid var(--line); background: white; border-radius: 6px; font-size: 11px; }
.filter-button svg { width: 14px; height: 14px; }
.filter-button span { min-width: 16px; height: 16px; display: grid; place-items: center; border-radius: 4px; color: white; background: var(--ink); font: 500 9px/1 "DM Mono", monospace; }

.filter-popover {
  position: absolute; z-index: 30; top: 48px; right: 20px; width: 210px; padding: 14px;
  background: white; border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 14px 40px rgba(24,32,29,.14);
}
.filter-title { margin-bottom: 10px; font-size: 12px; font-weight: 600; }
.filter-option { display: flex; align-items: center; gap: 8px; padding: 7px 0; color: #4f5a55; font-size: 11px; cursor: pointer; }
.filter-option input { accent-color: var(--green); }
.filter-option .device-swatch { width: 8px; height: 8px; border-radius: 2px; }

.calendar-wrap { height: calc(100vh - 262px); min-height: 530px; overflow: auto; position: relative; scrollbar-color: #bac5bf transparent; scrollbar-width: thin; }
.calendar { min-width: 850px; display: grid; grid-template-columns: 62px 1fr; grid-template-rows: 52px calc(var(--hour-h) * 24); position: relative; }
.calendar-corner { position: sticky; top: 0; left: 0; z-index: 15; background: #f8faf9; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; justify-content: center; padding-left: 12px; }
.calendar-corner span { color: #55615b; font: 500 9px/1 "DM Mono", monospace; }
.calendar-corner small { color: #9ba49f; font-size: 9px; margin-top: 5px; }
.day-headers { position: sticky; top: 0; z-index: 12; display: grid; grid-template-columns: repeat(7, 1fr); background: #f8faf9; border-bottom: 1px solid var(--line); }
.day-header { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; border-right: 1px solid var(--line); }
.day-header:last-child { border-right: 0; }
.day-header .day-name { font-size: 10px; color: var(--muted); }
.day-header .day-number { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 6px; font: 500 13px/1 "DM Mono", monospace; }
.day-header.today .day-name { color: var(--green); font-weight: 600; }
.day-header.today .day-number { background: var(--green); color: white; }
.time-axis { position: sticky; left: 0; z-index: 8; background: #fbfcfb; border-right: 1px solid var(--line); }
.time-mark { height: var(--hour-h); position: relative; border-bottom: 1px solid var(--line); color: #8a948f; font: 400 9px/1 "DM Mono", monospace; padding: 5px 0 0 11px; }
.calendar-grid { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); background-color: white; }
.day-column { position: relative; height: calc(var(--hour-h) * 24); border-right: 1px solid var(--line); cursor: crosshair; }
.day-column:last-child { border-right: 0; }
.day-column::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-h) - 1px), var(--line) calc(var(--hour-h) - 1px), var(--line) var(--hour-h)); }
.day-column.weekend { background: #fafbfa; }
.day-column.today { background: #fbfdfc; }
.booking {
  position: absolute; left: 5px; right: 5px; z-index: 3; border-radius: 5px; padding: 6px 7px; overflow: hidden; cursor: pointer;
  border-left: 3px solid currentColor; transition: transform .18s, filter .18s, box-shadow .18s; animation: booking-in .35s both;
}
.booking:hover { transform: translateY(-1px); filter: saturate(1.08); box-shadow: 0 6px 14px rgba(24,32,29,.12); z-index: 5; }
.booking strong, .booking span, .booking small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.booking strong { color: #23332d; font-size: 10px; line-height: 1.25; }
.booking span { margin-top: 3px; color: #54635d; font: 400 8px/1.2 "DM Mono", monospace; }
.booking small { margin-top: 4px; color: #6a7771; font-size: 8px; }
.booking.running { color: var(--green); background: var(--green-soft); }
.booking.booked { color: var(--blue); background: var(--blue-soft); }
.booking.maintenance { color: var(--purple); background: var(--purple-soft); }
.booking.completed { color: #8a948f; background: #edf0ee; opacity: .78; }
.booking.hidden-device { display: none; }
.current-time-line { position: absolute; z-index: 7; left: 0; right: 0; height: 1px; background: var(--red); pointer-events: none; }
.current-time-line::before { content: ""; position: absolute; width: 7px; height: 7px; border-radius: 50%; background: var(--red); left: -4px; top: -3px; }
.current-time-label { position: absolute; right: 4px; top: -8px; padding: 2px 4px; background: var(--red); color: white; border-radius: 3px; font: 500 8px/1 "DM Mono", monospace; }

.side-panel { background: #f7f9f8; }
.aside-section { padding: 20px; }
.aside-section + .aside-section { border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.section-heading h3 { margin: 5px 0 0; font-size: 15px; }
.instrument-list { display: flex; flex-direction: column; gap: 8px; }
.instrument {
  background: white; border: 1px solid var(--line); border-radius: 7px; padding: 11px 12px; cursor: pointer;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.instrument:hover { border-color: #b7c5be; transform: translateY(-1px); box-shadow: 0 6px 14px rgba(24,32,29,.06); }
.instrument-top, .instrument-bottom { display: flex; align-items: center; justify-content: space-between; }
.instrument-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.instrument-name i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.instrument-name strong { font-size: 11px; }
.instrument-name span { color: var(--muted); font: 400 8px/1 "DM Mono", monospace; }
.status-tag { padding: 3px 5px; border-radius: 3px; font-size: 8px; font-weight: 600; }
.status-tag.running { color: var(--green-dark); background: var(--green-soft); }
.status-tag.idle { color: #59645f; background: #e9edeb; }
.status-tag.maintenance { color: #685a95; background: var(--purple-soft); }
.progress-track { height: 3px; margin: 10px 0 8px; background: #e9edeb; border-radius: 3px; overflow: hidden; }
.progress-track span { display: block; height: 100%; background: var(--green); transition: width .6s ease; }
.instrument-bottom { color: var(--muted); font-size: 8px; }
.instrument-bottom strong { color: #4c5852; font: 500 8px/1 "DM Mono", monospace; }
.text-button { padding: 0; background: transparent; color: var(--green); font-size: 10px; }
.queue-list { display: flex; flex-direction: column; }
.queue-item { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 9px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.queue-time { color: var(--ink); font: 500 9px/1 "DM Mono", monospace; }
.queue-main { min-width: 0; }
.queue-main strong { display: block; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-main span { display: block; margin-top: 4px; color: var(--muted); font-size: 8px; }
.queue-device { width: 8px; height: 8px; border-radius: 2px; }
.queue-empty { margin: 0; padding: 12px 0; color: var(--muted); font-size: 10px; }

.booking-dialog { width: 590px; padding: 0; border: 0; border-radius: 8px; box-shadow: 0 26px 80px rgba(15,25,21,.28); }
.booking-dialog::backdrop { background: rgba(15,25,21,.46); backdrop-filter: blur(3px); }
.booking-dialog[open] { animation: dialog-in .22s ease-out; }
.booking-dialog form { padding: 22px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.dialog-header h2 { margin: 7px 0 0; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.form-field.full { grid-column: 1 / -1; }
.form-field span { color: #53605a; font-size: 11px; font-weight: 600; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; background: #fbfcfb; padding: 9px 10px; color: var(--ink); font-size: 12px; outline: none;
}
.form-field input, .form-field select { height: 38px; }
.form-field textarea { resize: vertical; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(15,118,110,.1); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.secondary-button { min-height: 38px; padding: 0 15px; border: 1px solid var(--line); border-radius: 7px; background: white; font-size: 12px; }
.danger-button { min-height: 38px; gap: 7px; padding: 0 15px; border: 1px solid #d66b62; border-radius: 7px; background: #fff5f4; color: #a33129; font-size: 12px; }
.danger-button:hover { background: #fee9e7; }
.danger-button:disabled { cursor: wait; opacity: .6; }
.danger-button svg { width: 15px; height: 15px; }
.detail-content { padding: 22px; }
.detail-dialog .dialog-header > div { min-width: 0; }
.detail-dialog h2 { overflow-wrap: anywhere; }
.booking-details { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin: 0; }
.booking-details div { min-width: 0; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.booking-details .full { grid-column: 1 / -1; }
.booking-details dt { color: var(--muted); font-size: 10px; }
.booking-details dd { margin: 5px 0 0; overflow-wrap: anywhere; color: var(--ink); font-size: 12px; line-height: 1.5; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 100; transform: translate(-50%, 18px); display: flex; align-items: center; gap: 9px; padding: 11px 15px; border-radius: 7px; background: var(--ink); color: white; font-size: 11px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; box-shadow: 0 10px 30px rgba(24,32,29,.22); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast svg { width: 15px; height: 15px; color: #67d1b5; }
.toast.error svg { color: #ff8a82; }

@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px #dff3e9; } 50% { box-shadow: 0 0 0 6px rgba(223,243,233,0); } }
@keyframes booking-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (max-width: 1200px) {
  body { min-width: 980px; }
  .workspace { grid-template-columns: minmax(730px, 1fr) 276px; }
  .overview { grid-template-columns: 220px 1fr; }
  .metric { padding-inline: 16px; }
  .legend { display: none; }
}

@media (max-width: 820px) {
  body { min-width: 0; }
  .topbar { height: 64px; padding: 0 14px; grid-template-columns: 1fr auto; }
  .live-clock { display: none; }
  .brand h1 { font-size: 15px; }
  .brand p { display: none; }
  .top-actions { display: none; }
  .mobile-booking-button {
    position: absolute; right: 14px; top: 13px; display: grid; place-items: center;
    width: 38px; height: 38px; border: 0; border-radius: 7px; background: var(--ink); color: white; cursor: pointer;
  }
  .mobile-booking-button svg { width: 18px; height: 18px; }
  .overview { height: auto; padding: 16px 14px; display: block; overflow-x: auto; }
  .overview-heading { display: flex; align-items: baseline; gap: 8px; margin-bottom: 14px; }
  .overview-heading h2 { font-size: 17px; }
  .overview-heading p, .overview-heading .eyebrow { display: none; }
  .metric-strip { min-width: 620px; }
  .metric { padding: 2px 16px; }
  .workspace { display: block; }
  .schedule-panel { border-right: 0; }
  .schedule-toolbar { padding: 0 10px; }
  .toolbar-controls { gap: 7px; }
  .today-button { display: none; }
  .week-label { padding-inline: 5px; }
  .calendar-wrap { height: calc(100vh - 236px); min-height: 500px; }
  .calendar { min-width: 880px; }
  .side-panel { display: none; }
  .booking-dialog { width: calc(100% - 24px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
