:root {
  --bg: #f7f9f8;
  --surface: #ffffff;
  --border: #dde3e0;
  --text: #1f2a24;
  --text-muted: #5b6b63;
  --green: #2e7d4f;
  --green-dark: #1f5c39;
  --green-light: #e6f3ea;
  --danger: #b3261e;
  --danger-light: #fbeceb;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--green-dark);
}

.topbar nav a {
  margin-right: 1rem;
  color: var(--text);
  font-weight: 500;
}

.topbar nav a:hover { color: var(--green-dark); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.stat {
  background: var(--green-light);
  border: 1px solid #c7e3d2;
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat .num { font-size: 1.8rem; font-weight: 700; color: var(--green-dark); }
.stat .label { color: var(--text-muted); font-size: 0.9rem; }

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

th, td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--text-muted); font-weight: 600; background: #fafbfa; }

tr:hover td { background: var(--green-light); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--green-light);
  color: var(--green-dark);
  border: 1px solid #c7e3d2;
}

.badge.priority-critical { background: var(--danger-light); color: var(--danger); border-color: #f0c9c6; }
.badge.priority-high { background: #fdf0e3; color: #a85b00; border-color: #f2d7b8; }

.badge.status-closed { background: #ececec; color: #555; border-color: #ddd; }

form.inline { display: inline; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.filters select, .filters input[type="text"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

input, select, textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  width: 100%;
  font-family: inherit;
}

label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 0.25rem; margin-top: 0.75rem; }

button, .btn {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

button:hover, .btn:hover { background: var(--green-dark); }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #9bd4b4;
  outline-offset: 1px;
}

.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f0f0f0; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem 0; }
.messages li {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}
.messages li.success { background: var(--green-light); color: var(--green-dark); border: 1px solid #c7e3d2; }
.messages li.error { background: var(--danger-light); color: var(--danger); border: 1px solid #f0c9c6; }

.comment { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; margin-bottom: 0.6rem; }
.comment.internal { background: #fff8e8; border-color: #f0e2bb; }
.comment.customer_visible { background: var(--green-light); border-color: #c7e3d2; }
.comment .meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; }

.audit-entry { font-size: 0.85rem; padding: 0.4rem 0; border-bottom: 1px dashed var(--border); color: var(--text-muted); }

@media (max-width: 640px) {
  .container { padding: 0.75rem; }
  table, thead, tbody, th, td, tr { display: block; }
  thead tr { position: absolute; top: -9999px; left: -9999px; }
  tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.6rem; padding: 0.4rem; }
  td { border: none; padding: 0.3rem 0.4rem; }
  td::before { content: attr(data-label); font-weight: 600; display: block; color: var(--text-muted); font-size: 0.75rem; }
}
