:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #fff;
  --text: #1f2329;
  --muted: #646a73;
  --line: #dee0e3;
  --brand: #1456f0;
  --brand-soft: #eef3ff;
  --ok: #168a4a;
  --ok-soft: #eaf8f0;
  --warn: #b76e00;
  --warn-soft: #fff7e6;
  --danger: #d83931;
  --danger-soft: #fff0f0;
  --shadow: 0 8px 24px rgba(31, 35, 41, .08);
}

* { box-sizing: border-box; }
html {
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: visible;
  touch-action: pan-y;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden], .hidden { display: none !important; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 58px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.app-header h1 { margin: 0; text-align: center; font-size: 18px; }
.icon-button {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 23px;
  text-decoration: none;
}
.app-header .icon-button.hidden { display: block !important; visibility: hidden; }

main {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  touch-action: pan-y;
}
main.workspace-main { width: min(1440px, 100%); }
.view { display: grid; gap: 14px; }
.stack { display: grid; gap: 12px; }
.view > *, .panel, .order-group, .table-wrap { min-width: 0; }
.panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(31, 35, 41, .03);
}
.panel-title, .panel-head, .toolbar, .item-head, .request-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-title { align-items: flex-start; margin-bottom: 12px; }
h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 0; font-size: 18px; }
h3 { margin-bottom: 8px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.project-field { width: calc((100% - 12px) / 2); }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, textarea, select {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 86, 240, .12);
}
input[readonly] { background: #f5f6f7; color: var(--muted); }
textarea { min-height: 120px; resize: vertical; }
.required, .required-mark, .field-error { color: var(--danger); }
.field-error { min-height: 18px; font-size: 12px; }
.invalid { border-color: var(--danger) !important; }

.combobox { position: relative; }
.combobox input { padding-right: 42px; }
.combobox-toggle {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}
.combobox-options {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}
.combobox-option, .combobox-empty {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  text-align: left;
}
.combobox-option:hover, .combobox-option:focus { background: var(--brand-soft); outline: none; }
.combobox-empty { color: var(--muted); }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid var(--brand);
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.button.secondary { border-color: var(--brand); background: #fff; color: var(--brand); }
.button.ghost { border-color: var(--line); background: #fff; color: var(--text); }
.button.danger { border-color: var(--danger); background: #fff; color: var(--danger); }
.button.full { width: 100%; }
.button.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .button { flex: 0 1 auto; }
.form-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.file-picker {
  position: relative;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.file-picker input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-picker strong { color: var(--brand); font-size: 13px; }

.feedback-toast {
  position: fixed;
  z-index: 30;
  top: calc(70px + env(safe-area-inset-top));
  left: 50%;
  width: min(560px, calc(100% - 24px));
  transform: translateX(-50%);
  padding: 12px 42px 12px 14px;
  border-radius: 10px;
  background: #303236;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.feedback-toast.error { background: var(--danger); }
.feedback-toast.ok { background: var(--ok); }
.feedback-toast button {
  position: absolute;
  top: 5px;
  right: 7px;
  width: auto;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 20px;
}
.detail-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; padding: 7px 0; border-bottom: 1px solid #f0f1f2; }
.detail-row:last-child { border-bottom: 0; }
.detail-row > span { color: var(--muted); }
.action-panel { display: grid; gap: 14px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }

@media (max-width: 640px) {
  main { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); }
  .grid { grid-template-columns: 1fr; }
  .project-field { width: 100%; }
  .detail-row { grid-template-columns: 88px minmax(0, 1fr); }
}
