:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #172b4d;
  --muted: #6b778c;
  --border: #dfe1e6;
  --accent: #0052cc;
  --accent-hover: #0747a6;
  --danger: #de350b;
  --nav: #0747a6;
  --todo: #6b778c;
  --progress: #0052cc;
  --review: #ff8b00;
  --done: #00875a;
  --rejected: #de350b;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--nav);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.65rem 1.25rem;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  letter-spacing: -0.02em;
}

.brand:hover { color: #fff; text-decoration: none; }

.topbar nav {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.voice-widget {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.voice-btn {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.voice-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.toolbar .voice-btn {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.toolbar .voice-btn:hover {
  background: #ebecf0;
}

.voice-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #ff5630;
  display: inline-block;
}

.voice-btn.is-recording {
  background: #ffebe6;
  border-color: #ff5630;
  color: #bf2600;
  animation: voice-pulse 1.2s ease-in-out infinite;
}

.topbar .voice-btn.is-recording {
  background: #ff5630;
  border-color: #ff5630;
  color: #fff;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 86, 48, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(255, 86, 48, 0); }
}

.voice-status {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.9);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar .voice-status {
  color: var(--muted);
  max-width: 280px;
}

.voice-status[data-kind="error"] { color: #ffbdad; }
.toolbar .voice-status[data-kind="error"] { color: var(--danger); }
.voice-status[data-kind="ok"] { color: #abf5d1; }
.toolbar .voice-status[data-kind="ok"] { color: var(--done); }

.voice-confirm-modal {
  max-width: min(520px, calc(100% - 2rem));
}

.confirm-fields {
  margin: 0 0 1rem;
  display: grid;
  gap: 0.75rem;
}

.confirm-fields > div {
  display: grid;
  gap: 0.2rem;
}

.confirm-fields dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.confirm-fields dd {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.voice-confirm-modal .voice-status {
  margin: 0.85rem 0 0;
  color: var(--muted);
}

.voice-confirm-modal .voice-btn {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.voice-confirm-modal .voice-btn.is-recording {
  background: #ffebe6;
  border-color: #ff5630;
  color: #bf2600;
}

.topbar nav > a:not(.btn) {
  color: rgba(255, 255, 255, 0.92);
  font-weight: 500;
}

.page {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.navbar.topbar {
  background: var(--nav) !important;
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}

.navbar.topbar .nav-link {
  color: rgba(255, 255, 255, 0.92) !important;
  font-weight: 500;
}

.navbar.topbar .navbar-toggler {
  border-color: rgba(255, 255, 255, 0.45);
}

.navbar.topbar .btn-light {
  color: var(--text);
}

.issue-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.9rem 1rem;
  color: var(--text);
}

.issue-card:hover {
  background: #fafbfc;
  color: var(--text);
}

.issue-card-title {
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.35;
}

.issue-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.issue-row {
  cursor: pointer;
}

.alert-error {
  --bs-alert-color: #842029;
  --bs-alert-bg: #f8d7da;
  --bs-alert-border-color: #f5c2c7;
}

.toolbar h1,
.issue-header h1 {
  margin: 0.15rem 0 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.breadcrumb { margin: 0; color: var(--muted); font-size: 0.85rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.issue-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.55rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 0.85rem;
  border-radius: 3px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: #ebecf0; text-decoration: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.topbar .btn-primary {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.topbar .btn-primary:hover { background: rgba(255, 255, 255, 0.24); }

.btn-danger {
  background: #fff;
  border-color: #ffbdad;
  color: var(--danger);
}

.btn-danger:hover { background: #ffebe6; }

.search {
  display: flex;
  gap: 0.5rem;
  min-width: 0;
  width: 100%;
  max-width: 480px;
}

.search input[type="search"],
.field input[type="text"],
.field textarea,
.field select,
.status-form select,
.upload-form input[type="file"],
.comment-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.5rem 0.7rem;
  font: inherit;
  background: #fff;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  width: 100%;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 3px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  text-decoration: none;
}

.chip span {
  background: #ebecf0;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  font-size: 0.75rem;
}

.chip:hover { background: #ebecf0; text-decoration: none; color: var(--text); }
.chip.active {
  background: #deebff;
  color: var(--accent);
  font-weight: 600;
}

.issue-table-wrap {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: auto;
}

.issue-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.issue-table th,
.issue-table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  font-size: 0.92rem;
}

.issue-table th {
  background: #fafbfc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.issue-table tbody tr {
  cursor: pointer;
}

.issue-table tbody tr:hover { background: #f4f5f7; }

.col-key { width: 110px; }
.col-summary { width: auto; }
.col-key a { font-weight: 600; white-space: nowrap; }
.row-sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.status-todo { background: var(--todo); }
.status-progress { background: var(--progress); }
.status-review { background: var(--review); }
.status-done { background: var(--done); }
.status-rejected { background: var(--rejected); }

.prio {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  background: #ebecf0;
  color: var(--muted);
}

.prio-high { background: #ffebe6; color: #bf2600; }
.prio-medium { background: #fff0b3; color: #172b4d; }
.prio-low { background: #ebecf0; color: #5e6c84; }

.issue-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem;
  width: 100%;
  align-items: start;
}

.issue-main,
.issue-side,
.form-panel {
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  width: 100%;
}

.panel h2,
.panel-head h2 {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.form-panel .field { margin-bottom: 1rem; }
.field label,
.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.88rem;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.help { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.85rem; }
.errorlist { color: var(--danger); margin: 0.35rem 0 0; padding-left: 1.1rem; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.details-list {
  margin: 0;
  display: grid;
  gap: 0.85rem;
}

.details-list > div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0.5rem;
  align-items: center;
}

.details-list dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.details-list dd { margin: 0; }

.status-form select { width: 100%; }

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.attachment-tile {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.attachment-preview {
  appearance: none;
  border: 1px solid var(--border);
  background: #fafbfc;
  border-radius: 3px;
  padding: 0;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attachment-preview:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.attachment-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  height: 100%;
  color: #fff;
  font-weight: 700;
}

.file-icon-ext {
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.file-icon-label {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.92;
}

.file-icon-word { background: #2b579a; }
.file-icon-excel { background: #217346; }
.file-icon-powerpoint { background: #c43e1c; }
.file-icon-pdf { background: #b30b00; }
.file-icon-text { background: #5e6c84; }
.file-icon-document { background: #0052cc; }
.file-icon-file { background: #8993a4; }

.attachment-caption {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.attachment-name {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.78rem;
}

.link-quiet {
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.link-quiet:hover { color: var(--accent); }

.link-danger {
  background: none;
  border: 0;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.upload-form,
.comment-form {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.upload-tile,
.upload-empty {
  position: relative;
  margin: 0;
}

.upload-empty {
  width: 100%;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  aspect-ratio: 1;
  border: 2px dashed #c1c7d0;
  border-radius: 3px;
  background:
    linear-gradient(180deg, #fafbfc 0%, #f4f5f7 100%);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 0.75rem;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.upload-placeholder:hover,
.upload-placeholder:focus-within {
  border-color: var(--accent);
  background: #deebff;
  color: var(--accent);
}

.upload-placeholder-lg {
  aspect-ratio: auto;
  min-height: 160px;
  padding: 1.5rem 1rem;
}

.upload-placeholder-icon {
  display: flex;
  color: inherit;
  opacity: 0.9;
}

.upload-placeholder-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: inherit;
}

.upload-placeholder-hint {
  font-size: 0.75rem;
  color: inherit;
  opacity: 0.85;
}

.upload-selected {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  word-break: break-word;
}

.comment-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.comment-list li {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.comment-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.prose { line-height: 1.55; }
.prose p:first-child { margin-top: 0; }
.prose p:last-child { margin-bottom: 0; }

.empty {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 3px;
  width: 100%;
}

.flash {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.flash li {
  padding: 0.7rem 0.9rem;
  border-radius: 3px;
  background: #deebff;
  border: 1px solid #b3d4ff;
}

.flash-error { background: #ffebe6 !important; border-color: #ffbdad !important; }
.flash-warning { background: #fff0b3 !important; border-color: #ffe380 !important; }
.flash-success { background: #e3fcef !important; border-color: #abf5d1 !important; }

.app-dialog {
  border: 0;
  padding: 0;
  border-radius: 3px;
  box-shadow: 0 8px 24px rgba(9, 30, 66, 0.25);
  max-width: min(440px, calc(100% - 2rem));
  width: 100%;
}

.app-dialog::backdrop,
.lightbox::backdrop,
.viewer-modal::backdrop {
  background: rgba(9, 30, 66, 0.54);
}

.app-dialog-card {
  margin: 0;
  padding: 1.25rem 1.3rem;
  background: var(--surface);
}

.app-dialog-card h2 {
  margin: 0 0 0.55rem;
  font-size: 1.15rem;
}

.app-dialog-card p {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.5;
}

.app-dialog-actions { justify-content: flex-end; }

.lightbox {
  border: 0;
  padding: 2.5rem 0.5rem 0.75rem;
  width: min(96vw, 1400px);
  max-width: 96vw;
  max-height: 96vh;
  background: transparent;
  overflow: visible;
  position: relative;
}

.lightbox-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 2;
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 999px;
  background: rgba(9, 30, 66, 0.72);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox-close:hover { background: rgba(9, 30, 66, 0.9); }

.lightbox img {
  display: block;
  max-width: 96vw;
  max-height: 88vh;
  margin: 0 auto;
  border-radius: 3px;
  background: #000;
}

.lightbox-caption {
  margin: 0.55rem 0 0;
  text-align: center;
  color: #fff;
  font-size: 0.9rem;
}

.viewer-modal {
  border: 0;
  padding: 0;
  width: min(96vw, 1200px);
  height: min(92vh, 900px);
  max-width: 96vw;
  max-height: 92vh;
  background: #fff;
  border-radius: 3px;
  overflow: hidden;
}

.viewer-modal[open] {
  display: flex;
  flex-direction: column;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  position: relative;
}

.viewer-toolbar strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 0.5rem;
}

.viewer-toolbar .lightbox-close {
  position: static;
  width: 2rem;
  height: 2rem;
  font-size: 1.35rem;
}

.viewer-modal iframe {
  border: 0;
  width: 100%;
  flex: 1;
  min-height: 0;
  background: #ebecf0;
}

.viewer-note {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  background: #fff7d6;
}

@media (max-width: 900px) {
  .issue-layout,
  .field-row { grid-template-columns: 1fr; }
  .col-key { width: 90px; }
}
