:root {
  --bg: #f6f8f7;
  --panel: #ffffff;
  --panel-border: #dde5e0;
  --panel-border-soft: #e8eeeb;
  --text: #16261d;
  --text-dim: #5c7267;
  --text-faint: #8ba095;

  --accent: #1f5e3f;
  --accent-dark: #143f2a;
  --accent-soft: #e6f0ea;
  --accent-line: #bcd9c8;

  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --status-open: #b3261e;
  --status-open-bg: #fbe9e7;
  --status-progress: #a6690a;
  --status-progress-bg: #fdf1de;
  --status-resolved: #1f5e3f;
  --status-resolved-bg: #e6f0ea;
  --status-closed: #4b5a53;
  --status-closed-bg: #eef1ef;
  --status-reopened: #9a3412;
  --status-reopened-bg: #fdece3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--accent-dark);
}

h1 {
  font-family: var(--sans);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 .badge { vertical-align: middle; }

h2 {
  font-size: 1rem;
  margin: 0 0 16px;
  color: var(--accent-dark);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(20, 63, 42, 0.04);
}

.hidden { display: none !important; }

.btn {
  font-family: var(--sans);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: #ffffff;
  color: var(--accent-dark);
  border-color: var(--panel-border);
}
.btn-secondary:hover { border-color: var(--accent); background: var(--accent-soft); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: transparent;
  padding: 6px 10px;
  font-size: 0.82rem;
}
.btn-ghost:hover { color: var(--accent-dark); background: var(--accent-soft); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 20px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }

label {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="date"],
input[type="file"],
select,
textarea {
  background: #ffffff;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 0.92rem;
}

input[type="file"] {
  padding: 6px 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; }

.form-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.filters input, .filters select {
  flex: 1 1 160px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

thead th {
  text-align: left;
  color: var(--text-dim);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  border-bottom: 2px solid var(--accent-dark);
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--panel-border-soft);
}

tbody tr { cursor: pointer; transition: background 0.12s ease; }
tbody tr:hover { background: var(--accent-soft); }

td.id-cell { font-family: var(--mono); color: var(--text-faint); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.badge-open { background: var(--status-open-bg); color: var(--status-open); }
.badge-in-progress { background: var(--status-progress-bg); color: var(--status-progress); }
.badge-resolved { background: var(--status-resolved-bg); color: var(--status-resolved); }
.badge-closed { background: var(--status-closed-bg); color: var(--status-closed); }
.badge-reopened { background: var(--status-reopened-bg); color: var(--status-reopened); }

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 30px 0;
}

/* Detail page */
.detail-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 24px;
}
.detail-item { display: flex; flex-direction: column; gap: 4px; }
.detail-item .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}
.detail-item .value { font-size: 0.95rem; }
.detail-item .value.empty { color: var(--text-faint); font-style: italic; }
.detail-full { grid-column: 1 / -1; }

.shot-link {
  color: var(--accent);
  font-size: 0.88rem;
  text-decoration: none;
  font-weight: 600;
}
.shot-link:hover { text-decoration: underline; }

.shot-preview {
  max-width: 220px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  display: block;
  margin-top: 6px;
}

.status-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  align-items: end;
}
.status-form button { grid-column: 1 / -1; justify-self: start; }

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 14px;
  position: relative;
  padding-bottom: 22px;
}
.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 4px;
  position: relative;
  z-index: 1;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px var(--accent-line);
}
.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 16px;
  bottom: -6px;
  width: 2px;
  background: var(--panel-border);
}

.timeline-content { font-size: 0.9rem; }
.timeline-time {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.timeline-note {
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* Sidebar layout */
.app-layout {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  font-family: var(--sans);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-dark);
  letter-spacing: -0.01em;
  padding: 0 6px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 0 6px;
  margin-bottom: 2px;
}

.sheet-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 7px;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease;
}

.sheet-item:hover {
  background: var(--accent-soft);
}

.sheet-item.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.sheet-item-name {
  font-size: 0.89rem;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.sheet-item.active .sheet-item-name {
  color: var(--accent-dark);
}

.sheet-item-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.12s ease;
}

.sheet-item:hover .sheet-item-actions,
.sheet-item.active .sheet-item-actions {
  opacity: 1;
}

.icon-btn {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 0.8rem;
  border-radius: 5px;
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { background: #ffffff; color: var(--accent-dark); }
.icon-btn.delete-btn:hover { color: var(--status-open); }

.sidebar-add-btn {
  width: 100%;
  text-align: center;
  margin-top: 6px;
}

.main-content {
  flex: 1;
  min-width: 0;
}

.main-content .container {
  margin: 0;
  max-width: none;
}

@media (max-width: 800px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }
}

@media (max-width: 600px) {
  .form-grid, .detail-grid, .status-form { grid-template-columns: 1fr; }
  header { flex-direction: column; align-items: flex-start; gap: 14px; }
  .detail-header-row { flex-direction: column; }
}