:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #eef1f5;
  --text: #20242c;
  --muted: #69717d;
  --line: #d9dee7;
  --accent: #1167b1;
  --accent-2: #0f8b8d;
  --danger: #c83e4d;
  --warning: #b86b00;
  --success: #2f855a;
  --ink: #111827;
  --shadow: 0 12px 26px rgba(25, 34, 45, .12);
  --radius: 8px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

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

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 7px;
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover { border-color: #aeb7c4; }

.button-link {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 600;
}

.button-link:hover { border-color: #aeb7c4; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.danger {
  background: #fff5f6;
  border-color: #efb6bd;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

header {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  padding: 16px 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 230px;
}

.mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

h1 {
  font-size: 20px;
  margin: 0;
  line-height: 1.15;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.user-pill {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.icon-btn {
  width: 42px;
  min-width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-weight: 700;
}

.filters {
  padding: 12px 20px;
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(150px, .8fr) minmax(150px, .8fr) minmax(150px, .8fr) auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  gap: 10px;
  padding: 14px 20px 0;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  min-height: 72px;
}

.metric strong {
  display: block;
  font-size: 23px;
  line-height: 1;
  margin-bottom: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

main {
  overflow: hidden;
  padding: 14px 20px 20px;
}

.board {
  height: calc(100vh - 222px);
  min-height: 460px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(286px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.column {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 286px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.column-head {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.column-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.column-title h2 {
  font-size: 15px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.count {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
}

.wip {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.wip.hot { color: var(--danger); font-weight: 700; }

.dropzone {
  overflow-y: auto;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.dropzone.drag-over { background: #e7f3f3; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: 0 5px 14px rgba(30, 42, 58, .08);
  display: grid;
  gap: 8px;
  cursor: grab;
  min-height: 164px;
}

.card:active { cursor: grabbing; }
.card.urgent { border-left-color: var(--danger); }
.card.high { border-left-color: var(--warning); }
.card.normal { border-left-color: var(--accent); }
.card.low { border-left-color: var(--success); }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.order-id {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.card h3 {
  font-size: 15px;
  margin: 2px 0 0;
  line-height: 1.25;
  word-break: break-word;
}

.badge {
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.urgent { background: #ffe7ea; color: var(--danger); }
.badge.high { background: #fff2d8; color: var(--warning); }
.badge.normal { background: #e6f0fb; color: var(--accent); }
.badge.low { background: #e6f4ec; color: var(--success); }

.customer {
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

.card-meta {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.due.overdue { color: var(--danger); font-weight: 800; }
.due.soon { color: var(--warning); font-weight: 800; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  background: #edf2f7;
  border: 1px solid #dce3ec;
  color: #475569;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
}

.progress {
  height: 7px;
  background: #e4e9f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent-2);
}

dialog {
  width: min(820px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop { background: rgba(10, 15, 22, .42); }

.modal-head {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-head h2 {
  font-size: 18px;
  margin: 0;
}

.modal-body {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field.full { grid-column: 1 / -1; }

.detail-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  padding: 12px;
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.detail-head h3 {
  margin: 0;
  font-size: 15px;
}

.task-compose {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(130px, .6fr) 150px auto;
  gap: 8px;
  margin-bottom: 10px;
}

.task-list,
.comment-list {
  display: grid;
  gap: 8px;
}

.task-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 9px;
}

.task-item.done .task-title {
  text-decoration: line-through;
  color: var(--muted);
}

.task-title {
  font-weight: 700;
  word-break: break-word;
}

.task-meta,
.comment-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.task-item input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.comment-compose {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.comment-compose textarea {
  min-height: 70px;
}

.comment-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.comment-body {
  white-space: pre-wrap;
  line-height: 1.45;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 5px;
}

.modal-actions {
  padding: 12px 16px 16px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
}

.right-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.empty {
  border: 1px dashed #b7c0cd;
  color: var(--muted);
  border-radius: var(--radius);
  min-height: 86px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
  font-size: 13px;
}

.error-banner {
  background: #fff5f6;
  border: 1px solid #efb6bd;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 12px;
}

.install-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #eef1f5;
}

.auth-panel {
  width: min(430px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.auth-brand { margin-bottom: 18px; }

.stack-form {
  display: grid;
  gap: 12px;
}

.muted-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.admin-shell {
  min-height: 100vh;
  background: var(--bg);
}

.admin-main {
  height: auto;
  min-height: calc(100vh - 72px);
  overflow: visible;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 14px;
}

.admin-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.admin-panel h2 {
  font-size: 17px;
  margin: 0 0 14px;
}

.admin-panel.wide {
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
}

.check-row input {
  width: auto;
  min-height: auto;
}

.row-editor summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

.inline-form {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 8px;
}

.form-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

.install-panel {
  width: min(680px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.install-panel p { color: var(--muted); }
.install-panel form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.install-panel a { color: var(--accent); font-weight: 700; }
.notice { border-radius: var(--radius); padding: 12px; margin: 12px 0; }
.notice.success { background: #e6f4ec; color: var(--success); }
.notice.error { background: #fff5f6; color: var(--danger); }

@media (max-width: 980px) {
  header {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar { justify-content: flex-start; }

  .filters { grid-template-columns: 1fr 1fr; }
  .filters button { grid-column: 1 / -1; }
  .metrics { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .board { height: calc(100vh - 340px); }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  header, .filters, .metrics, main { padding-left: 12px; padding-right: 12px; }
  .filters, .modal-body { grid-template-columns: 1fr; }
  .task-compose { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr; }
  .board {
    grid-auto-columns: minmax(280px, 88vw);
    min-height: 430px;
  }
  .modal-actions { flex-direction: column; }
  .right-actions { justify-content: stretch; }
  .right-actions button, .modal-actions > button { width: 100%; }
}
