/* ============================================================== tokens */
:root {
  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --surface-2: #fafbfc;
  --line:      #e1e4e8;
  --line-soft: #eceef1;
  --text:      #1c2128;
  --text-2:    #57606a;
  --text-3:    #8b949e;
  --accent:    #3164d6;
  --accent-2:  #2450b5;
  --accent-bg: #e8f0fe;
  --danger:    #c1301f;
  --danger-bg: #fdeceb;
  --shadow-sm: 0 1px 2px rgba(27, 31, 36, .07);
  --shadow-md: 0 4px 14px rgba(27, 31, 36, .10);
  --shadow-lg: 0 16px 48px rgba(27, 31, 36, .18);
  --r:   8px;
  --r-s: 6px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg:        #0f1216;
  --surface:   #171b21;
  --surface-2: #1d222a;
  --line:      #2a313b;
  --line-soft: #232932;
  --text:      #e5e9ef;
  --text-2:    #9aa4b2;
  --text-3:    #6e7885;
  --accent:    #5b8cf5;
  --accent-2:  #7ba3f8;
  --accent-bg: #1b2740;
  --danger:    #f0776a;
  --danger-bg: #3a1e1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ============================================================ controls */
button {
  font: inherit; cursor: pointer; border-radius: var(--r-s);
  padding: 7px 13px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s, transform .06s;
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--line-soft); color: var(--text); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-bg); }
button.block { width: 100%; justify-content: center; }
.icon-btn { padding: 7px; border-color: transparent; background: transparent; color: var(--text-2); }
.icon-btn:hover { background: var(--line-soft); color: var(--text); }

input, select, textarea {
  font: inherit; width: 100%; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
textarea { resize: vertical; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; line-height: 1.6; }
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 12.5px; color: var(--text-2); }
label input, label select, label textarea { margin-top: 5px; font-weight: 400; color: var(--text); }

.muted { color: var(--text-3); font-weight: 400; }
.error { color: var(--danger); margin: 8px 0 0; font-size: 13px; }
.req { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* =============================================================== login */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--surface); padding: 34px; border-radius: 12px;
  border: 1px solid var(--line); width: 360px; box-shadow: var(--shadow-md);
}
.login-mark, .mark {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-weight: 700; border-radius: 8px;
}
.login-mark { width: 42px; height: 42px; font-size: 16px; margin-bottom: 16px; }
.mark { width: 24px; height: 24px; font-size: 11px; border-radius: 6px; }
.login-card h1 { margin: 0 0 3px; font-size: 21px; }
.login-card > p { margin: 0 0 24px; font-size: 13px; }

/* =============================================================== shell */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 0 18px; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 9px; font-size: 14.5px; }
.views { display: flex; gap: 2px; background: var(--line-soft); padding: 3px; border-radius: var(--r-s); }
.view-btn { border: none; background: transparent; color: var(--text-2); padding: 5px 12px; font-size: 13px; }
.view-btn:hover { background: transparent; color: var(--text); }
.view-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.who { color: var(--text-2); font-size: 13px; margin: 0 6px; }

/* =============================================================== stats */
.stats { display: flex; gap: 10px; padding: 14px 18px 0; flex-wrap: wrap; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 16px; min-width: 108px;
}
.stat .n { font-size: 20px; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: 11.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.stat.hot .n { color: var(--danger); }
.stat.go .n { color: var(--accent); }

/* ============================================================= toolbar */
.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 18px; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search-wrap .search-icon { position: absolute; left: 10px; top: 9px; color: var(--text-3); }
.search-wrap input { padding-left: 32px; }
.toolbar select { width: auto; min-width: 130px; }
.toolbar .count { margin-left: auto; color: var(--text-3); font-size: 13px; }

/* =============================================================== board */
main { padding: 0 18px 18px; }
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.col {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r);
  width: 288px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 210px);
}
.col-head {
  display: flex; align-items: center; gap: 8px; padding: 11px 13px;
  border-bottom: 1px solid var(--line); font-weight: 600; font-size: 12.5px;
}
.col-head .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.col-head .n { margin-left: auto; color: var(--text-3); font-weight: 600; font-size: 12px;
               background: var(--line-soft); padding: 1px 7px; border-radius: 10px; }
.col-body { padding: 9px; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; flex: 1; min-height: 70px; }
.col.drop-target { border-color: var(--accent); }
.col.drop-target .col-body { background: var(--accent-bg); border-radius: 0 0 var(--r) var(--r); }
.col-empty { color: var(--text-3); font-size: 12.5px; text-align: center; padding: 18px 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-s);
  padding: 11px 12px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.card.dragging { opacity: .45; }
.card .r1 { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.card .key { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--text-3); }
.card .title { font-weight: 600; font-size: 13.2px; line-height: 1.45; }
.card .r2 { display: flex; align-items: center; gap: 6px; margin-top: 9px; flex-wrap: wrap; }

/* ================================================================ list */
.list-view { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
table.tasks { width: 100%; border-collapse: collapse; }
table.tasks th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
}
table.tasks td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tasks tr:last-child td { border-bottom: none; }
table.tasks tbody tr { cursor: pointer; }
table.tasks tbody tr:hover { background: var(--surface-2); }
table.tasks .t-key { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--text-3); white-space: nowrap; }
table.tasks .t-title { font-weight: 600; }

/* ============================================================== chips */
.badge, .prio, .label-chip, .avatar {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; white-space: nowrap; border-radius: 20px; padding: 2px 9px;
}
.s-New              { background: #fff2d6; color: #8a5a00; }
.s-Confirmed        { background: #ffe2e0; color: #a52d21; }
.s-InProgress       { background: #dce8ff; color: #23509e; }
.s-Fixedneedsretest { background: #e6e0ff; color: #4a35a0; }
.s-Closed           { background: #d9f2e0; color: #1d6b39; }
.s-Rejected         { background: #e8eaed; color: #5a626b; }
[data-theme="dark"] .s-New              { background: #4a3a10; color: #f5cf7d; }
[data-theme="dark"] .s-Confirmed        { background: #4d2320; color: #f6a49a; }
[data-theme="dark"] .s-InProgress       { background: #1f3565; color: #a8c4ff; }
[data-theme="dark"] .s-Fixedneedsretest { background: #322a5e; color: #c2b4ff; }
[data-theme="dark"] .s-Closed           { background: #17402a; color: #8fdcab; }
[data-theme="dark"] .s-Rejected         { background: #2c323b; color: #9aa4b2; }

.prio { padding: 1px 8px; font-size: 10.5px; letter-spacing: .02em; }
.prio::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.p-Critical { color: #c1301f; background: #fdeceb; }
.p-High     { color: #b45309; background: #fdf1dc; }
.p-Medium   { color: #23509e; background: #e6eeff; }
.p-Low      { color: #5a626b; background: #eceef1; }
[data-theme="dark"] .p-Critical { color: #f0776a; background: #3a1e1c; }
[data-theme="dark"] .p-High     { color: #e8a33d; background: #3a2c12; }
[data-theme="dark"] .p-Medium   { color: #7ba3f8; background: #1b2740; }
[data-theme="dark"] .p-Low      { color: #9aa4b2; background: #262c35; }

.label-chip { background: var(--line-soft); color: var(--text-2); font-weight: 500; padding: 1px 8px; }
.avatar {
  width: 22px; height: 22px; padding: 0; justify-content: center; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 10px; letter-spacing: -.02em;
}
.avatar.none { background: var(--line-soft); color: var(--text-3); border: 1px dashed var(--line); }
.card .r2 .avatar { margin-left: auto; }
.fix-dot { color: #1d6b39; display: inline-flex; }
[data-theme="dark"] .fix-dot { color: #8fdcab; }

/* ============================================================== drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 18, 22, .38); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 94vw); z-index: 50;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg); overflow-y: auto; padding: 22px 26px 40px;
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.drawer-head h1 { font-size: 19px; margin: 0; flex: 1; line-height: 1.4; }
.drawer-meta {
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
  color: var(--text-3); font-size: 12.5px;
  padding: 14px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.drawer-meta .field { display: flex; align-items: center; gap: 6px; }
.drawer-meta select { width: auto; padding: 3px 8px; font-size: 12.5px; }
.drawer-meta b { color: var(--text); font-weight: 600; }

.section-title {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin: 24px 0 9px;
}
.md {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r); padding: 2px 18px;
}
.md.empty-box { color: var(--text-3); padding: 14px 18px; font-style: italic; }
.md table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--line-soft); font-weight: 600; }
.md code { background: var(--line-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px;
           font-family: ui-monospace, Consolas, monospace; }
.md pre { background: var(--line-soft); padding: 12px; border-radius: var(--r-s); overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md h1, .md h2, .md h3 { font-size: 15px; margin: 20px 0 8px; }
.md blockquote { border-left: 3px solid var(--accent); margin: 12px 0; padding: 2px 14px; color: var(--text-2); }
.md > :first-child { margin-top: 14px; }
.md a { color: var(--accent); }

.comment { border-top: 1px solid var(--line-soft); padding: 12px 0; }
.comment:first-child { border-top: none; }
.comment .head { color: var(--text-3); font-size: 12px; margin-bottom: 5px; }
.comment .head b { color: var(--text); }
.comment.event { color: var(--text-3); font-size: 12.5px; padding: 7px 0; }
.comment.event .md { background: none; border: none; padding: 0; display: inline; }
.comment.event .md p { display: inline; margin: 0; }
.comment .md { font-size: 13.5px; }
#comment-box { margin-top: 14px; }
#comment-box textarea { font-family: inherit; font-size: 13.5px; }
#comment-box button { margin-top: 8px; }

/* ============================================================= dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 22px 26px 26px;
  width: min(800px, 94vw); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(15, 18, 22, .45); }
.dlg-head { display: flex; align-items: center; margin: 0 0 20px; }
.dlg-head h2 { margin: 0; font-size: 17px; flex: 1; }
dialog h3 { margin: 24px 0 12px; font-size: 14px; }
dialog menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 20px 0 0; }
table.users { width: 100%; border-collapse: collapse; font-size: 13px; }
table.users th, table.users td { border-bottom: 1px solid var(--line-soft); padding: 8px; text-align: left; }
table.users th { color: var(--text-3); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }

.editor { margin-bottom: 14px; }
.editor-tabs { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.editor-label { font-weight: 600; font-size: 12.5px; color: var(--text-2); margin-right: auto; }
.tab { border: none; background: transparent; color: var(--text-3); font-size: 12.5px; padding: 4px 10px; }
.tab.active { background: var(--line-soft); color: var(--text); }
.preview { min-height: 200px; max-height: 420px; overflow-y: auto; }

/* ============================================================== toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
          display: flex; flex-direction: column; gap: 8px; z-index: 90; align-items: center; }
.toast {
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 20px;
  font-size: 13px; box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 7px;
  animation: rise .18s ease-out;
}
.toast.bad { background: var(--danger); color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.empty { color: var(--text-3); padding: 50px 0; text-align: center; }

@media (max-width: 820px) {
  .stats { overflow-x: auto; flex-wrap: nowrap; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar { gap: 10px; padding: 0 12px; }
  .who { display: none; }
  main, .toolbar, .stats { padding-left: 12px; padding-right: 12px; }
  .col { max-height: none; }
  .drawer { padding: 18px 16px 40px; }
  table.tasks .hide-sm { display: none; }
}
