:root {
  --navy: #0f2742;
  --navy-2: #16395f;
  --blue: #1d6fdc;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e7ee;
  --ink: #1c2733;
  --muted: #61708099;
  --muted-solid: #5f6f80;
  --green: #1f8a4c;
  --amber: #b7791f;
  --red: #c0392b;
  --teal: #11808f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 56, .06), 0 4px 16px rgba(16, 32, 56, .05);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--navy);
  color: #fff;
  padding: 0 24px; height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--blue); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .5px;
}
.brand-text { font-size: 15px; }
.mainnav { display: flex; gap: 4px; margin-left: 8px; }
.mainnav a { color: #cdd9e8; padding: 8px 12px; border-radius: 7px; font-size: 14px; }
.mainnav a:hover { background: var(--navy-2); text-decoration: none; }
.mainnav a.active { background: var(--navy-2); color: #fff; }
.userbox { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.user-name { font-size: 14px; font-weight: 600; }
.user-roles { font-size: 11px; color: #9fb2c9; }
.link-btn { background: none; border: none; color: #9fb2c9; cursor: pointer; padding: 0; font-size: 12px; }
.link-btn:hover { color: #fff; text-decoration: underline; }
.switch-form { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.switch-label { font-size: 11px; color: #9fb2c9; text-transform: uppercase; letter-spacing: .4px; }
.switch-form select { background: var(--navy-2); color: #fff; border: 1px solid #2c4a6e; border-radius: 7px; padding: 5px 8px; font-size: 13px; cursor: pointer; max-width: 280px; }
.switch-form select:focus { outline: 2px solid var(--blue); }

.container { max-width: 1080px; margin: 28px auto; padding: 0 24px; }

/* Flash */
.flash { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.flash-success { background: #e8f6ee; color: #176b3a; border-color: #bfe6cf; }
.flash-error { background: #fdeceb; color: #a02c1f; border-color: #f4c9c4; }
.flash-info { background: #e9f1fb; color: #1a4f93; border-color: #c6dcf6; }

/* Headings */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .sub { color: var(--muted-solid); font-size: 14px; margin-top: 2px; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 20px; }
.card > h2 { display: flex; align-items: center; gap: 8px; }
.card .count { background: var(--bg); color: var(--muted-solid); border-radius: 20px; padding: 1px 9px; font-size: 12px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted-solid); font-weight: 600; }
tr:last-child td { border-bottom: none; }
.empty { color: var(--muted-solid); font-size: 14px; padding: 8px 2px; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-gray { background: #eef1f5; color: #5f6f80; }
.badge-blue { background: #e7f0fd; color: #1a5fc0; }
.badge-amber { background: #fbf0db; color: #98620f; }
.badge-teal { background: #ddf4f6; color: #0c6b78; }
.badge-green { background: #e3f5ea; color: #16703c; }
.badge-red { background: #fce7e4; color: #b23022; }

/* Buttons */
.btn { display: inline-block; border: 1px solid var(--blue); background: var(--blue); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn:hover { background: #195fbe; text-decoration: none; }
.btn-secondary { background: #fff; color: var(--navy); border-color: var(--line); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--red); border-color: #f0c6c0; }
.btn-danger:hover { background: #fdeceb; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-save { background: #bfe3cd; border-color: #a9d6bd; color: #236a47; transition: background .15s, box-shadow .15s, color .15s; }
.btn-save:hover { background: #aedcc1; text-decoration: none; }
.btn-save.dirty { background: #15a34a; border-color: #15a34a; color: #fff; box-shadow: 0 0 0 3px rgba(21,163,74,.20); }
.btn-save.dirty:hover { background: #138f41; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #36454f; }
input[type=text], input[type=email], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .field-row { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--muted-solid); font-weight: 400; margin-top: 4px; }
.checks { display: flex; flex-direction: column; gap: 7px; }
.checks label, .ack label { font-weight: 400; display: flex; gap: 9px; align-items: flex-start; margin: 0; }
.checks input, .ack input { width: auto; margin-top: 3px; }
.ack { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }

/* Errors list */
.errors { background: #fdeceb; border: 1px solid #f4c9c4; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; }
.errors ul { margin: 6px 0 0; padding-left: 18px; }
.errors li { color: #a02c1f; font-size: 14px; }

/* Detail meta */
.meta-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 28px; }
@media (max-width: 640px) { .meta-grid { grid-template-columns: 1fr; } }
.meta-grid .k { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted-solid); }
.meta-grid .v { font-size: 14px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.timeline .t-action { font-weight: 600; font-size: 14px; }
.timeline .t-meta { font-size: 12px; color: var(--muted-solid); }
.timeline .t-comment { font-size: 13px; background: var(--bg); border-radius: 7px; padding: 7px 10px; margin-top: 5px; }

/* Login */
.login-wrap { max-width: 920px; margin: 48px auto; display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
@media (max-width: 760px) { .login-wrap { grid-template-columns: 1fr; } }
.login-card h1 { font-size: 22px; margin-top: 0; }
.demo-users td { font-size: 13px; }
.demo-users code { background: var(--bg); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

.section-note { font-size: 13px; color: var(--muted-solid); margin: -6px 0 14px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.muted { color: var(--muted-solid); }
.right { text-align: right; }
.sitefoot { max-width: 1080px; margin: 30px auto; padding: 16px 24px; display: flex; justify-content: space-between; color: var(--muted-solid); font-size: 12px; flex-wrap: wrap; gap: 8px; }
.inline-form { display: inline; }

/* Email preview modal (dev mode: shows what a notification would send) */
.email-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 39, 66, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto;
}
.email-modal {
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(16, 32, 56, .28);
  width: 100%; max-width: 580px; overflow: hidden;
}
.email-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.email-modal-head h2 { margin: 0; font-size: 16px; }
.email-modal-close { background: none; border: none; font-size: 24px; line-height: 1; color: var(--muted-solid); cursor: pointer; padding: 0 4px; }
.email-modal-close:hover { color: var(--ink); }
.email-dev-banner { background: #fbf0db; color: #98620f; font-size: 13px; padding: 10px 20px; border-bottom: 1px solid #f0dca8; }
.email-modal-body { padding: 16px 20px; max-height: 60vh; overflow-y: auto; }
.email-preview { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; background: #fff; }
.email-preview:last-child { margin-bottom: 0; }
.email-row { display: flex; gap: 10px; font-size: 13px; padding: 2px 0; }
.email-k { flex: 0 0 64px; color: var(--muted-solid); text-transform: uppercase; font-size: 11px; letter-spacing: .4px; padding-top: 2px; }
.email-v { flex: 1; word-break: break-word; }
.email-body { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.email-modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }

/* ============================================================
   Mobile responsiveness
   ============================================================ */

/* Tablet / small-desktop: let the topbar wrap instead of overflowing. */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    padding: 10px 16px;
    gap: 10px 16px;
  }
  .mainnav { flex-wrap: wrap; margin-left: 0; }
  .userbox { margin-left: auto; }
  .container { padding: 0 16px; margin-top: 20px; }
  .sitefoot { padding: 16px; }
}

/* Phones: stack the topbar, full-width role switcher, card-style tables. */
@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .brand { justify-content: flex-start; }
  .mainnav {
    gap: 4px;
    margin-left: 0;
    border-top: 1px solid var(--navy-2);
    border-bottom: 1px solid var(--navy-2);
    padding: 8px 0;
  }
  .mainnav a { padding: 8px 10px; }
  .userbox {
    margin-left: 0;
    width: 100%;
    align-items: stretch;
  }
  .switch-form {
    width: 100%;
    align-items: stretch;
    gap: 4px;
  }
  .switch-form select { max-width: 100%; width: 100%; }

  .container { padding: 0 12px; }
  .card { padding: 16px 14px; }
  .page-head h1 { font-size: 20px; }

  /* Turn each request row into a stacked card with inline labels. */
  .req-table { font-size: 14px; }
  .req-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .req-table, .req-table tbody, .req-table tr, .req-table td { display: block; width: 100%; }
  .req-table tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px 12px;
    margin-bottom: 12px;
    background: #fff;
  }
  .req-table tr:last-child { margin-bottom: 0; }
  .req-table td {
    border-bottom: 1px solid var(--line);
    padding: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    text-align: right;
  }
  .req-table tr td:last-child { border-bottom: none; }
  .req-table td::before {
    content: attr(data-label);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted-solid);
    font-weight: 600;
    text-align: left;
    flex: 0 0 auto;
  }
  .req-table td .muted { text-align: right; }
}
