:root {
  color-scheme: light;
  --ink: #14231f;
  --muted: #66766f;
  --green: #1d3a32;
  --green-2: #2d594c;
  --mint: #d9e8df;
  --cream: #f5f1e8;
  --paper: rgba(255, 255, 255, 0.88);
  --line: #dce3de;
  --gold: #cf9f4a;
  --danger: #b54436;
  --shadow: 0 24px 70px rgba(27, 54, 47, 0.12);
  font-family: Inter, "Noto Sans Thai", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--cream); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.ambient { position: fixed; border-radius: 999px; filter: blur(2px); pointer-events: none; opacity: .52; }
.ambient-one { width: 460px; height: 460px; right: -160px; top: -180px; background: #c2d8cc; }
.ambient-two { width: 360px; height: 360px; left: -140px; bottom: -170px; background: #ead6ad; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; }
.login-card { width: min(100%, 430px); padding: 48px; text-align: center; background: var(--paper); border: 1px solid rgba(255,255,255,.9); border-radius: 30px; box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.brand-mark { width: 62px; height: 62px; margin: 0 auto 22px; display: grid; place-items: center; border-radius: 19px; background: var(--green); color: #fff; font: 800 28px Georgia, serif; box-shadow: 0 10px 26px rgba(29,58,50,.25); }
.brand-mark.small { width: 38px; height: 38px; margin: 0; border-radius: 12px; font-size: 18px; box-shadow: none; }
.eyebrow { margin: 0 0 8px; font-size: 11px; letter-spacing: .19em; font-weight: 800; color: var(--green-2); }
h1, h2, p { margin-top: 0; }
.login-card h1 { margin-bottom: 12px; font: 700 42px/1.05 Georgia, "Times New Roman", serif; }
.muted, .intro-copy p { color: var(--muted); line-height: 1.7; }
.google-signin { min-height: 46px; margin-top: 28px; display: flex; justify-content: center; }
.form-error { color: var(--danger); margin: 16px 0 0; font-size: 14px; }

.app-view { min-height: 100vh; position: relative; }
.topbar { height: 72px; padding: 0 max(24px, calc((100vw - 1180px) / 2)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 24px; background: rgba(245,241,232,.82); border-bottom: 1px solid rgba(29,58,50,.1); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; width: fit-content; }
.brand span:last-child { display: grid; line-height: 1.05; }
.brand strong { letter-spacing: .12em; font-size: 14px; }
.brand small { color: var(--muted); font-size: 11px; }
.primary-nav { display: flex; gap: 6px; padding: 5px; background: rgba(255,255,255,.64); border: 1px solid rgba(29,58,50,.09); border-radius: 14px; }
.nav-button, .scope-button { border: 0; background: transparent; border-radius: 10px; padding: 9px 15px; cursor: pointer; font-weight: 650; font-size: 14px; }
.nav-button.active, .scope-button.active { background: var(--green); color: white; box-shadow: 0 6px 16px rgba(29,58,50,.16); }
.badge { display: inline-grid; min-width: 19px; height: 19px; padding: 0 5px; margin-left: 4px; place-items: center; border-radius: 10px; background: var(--gold); color: var(--ink); font-size: 10px; }
.user-area { justify-self: end; display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 13px; font-weight: 700; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.7); cursor: pointer; font-size: 20px; }

.content-shell { width: min(100% - 36px, 950px); margin: 0 auto; padding: 62px 0 90px; }
.view-panel { display: none; }
.view-panel.active { display: block; animation: rise .24s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.intro-copy { max-width: 620px; margin-bottom: 30px; }
.intro-copy h1, .history-heading h1 { margin-bottom: 10px; font: 700 clamp(34px, 6vw, 54px)/1.05 Georgia, "Times New Roman", serif; }

.issue-form { padding: 28px; background: var(--paper); border: 1px solid rgba(255,255,255,.88); border-radius: 24px; box-shadow: var(--shadow); }
.field { display: grid; gap: 9px; margin-bottom: 22px; }
.field > span { font-size: 13px; font-weight: 750; }
.field small { justify-self: end; color: var(--muted); }
select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 13px; background: #fff; color: var(--ink); outline: 0; transition: border .18s, box-shadow .18s; }
select { height: 50px; padding: 0 14px; }
textarea { padding: 15px; resize: vertical; min-height: 150px; line-height: 1.65; }
select:focus, textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 4px rgba(45,89,76,.10); }
.drop-zone { min-height: 126px; display: grid; place-items: center; align-content: center; gap: 5px; border: 1.5px dashed #9eaaa5; border-radius: 16px; cursor: pointer; text-align: center; background: rgba(217,232,223,.24); transition: .18s; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green-2); background: rgba(217,232,223,.55); }
.drop-zone input { position: absolute; opacity: 0; pointer-events: none; }
.drop-zone span:last-child { font-size: 12px; color: var(--muted); }
.upload-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: #fff; font-size: 20px; }
.image-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 12px; }
.preview-item { position: relative; aspect-ratio: 4/3; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #eef1ef; }
.preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-remove { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 9px; background: rgba(20,35,31,.78); color: white; cursor: pointer; }
.primary-button { width: 100%; margin-top: 24px; min-height: 54px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; border: 0; border-radius: 14px; background: var(--green); color: white; font-weight: 800; cursor: pointer; box-shadow: 0 12px 26px rgba(29,58,50,.22); }
.primary-button:disabled { opacity: .56; cursor: wait; }
.secondary-button { min-height: 42px; padding: 0 17px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.76); color: var(--green); cursor: pointer; font-weight: 750; }
.secondary-button:hover { border-color: var(--green-2); background: #fff; }
.form-message { margin: 16px 0 -10px; padding: 12px 14px; border-radius: 11px; background: #ecf5ef; color: var(--green); font-size: 13px; }
.form-message.error { background: #fbebe8; color: var(--danger); }

.history-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 25px; }
.scope-switch { display: flex; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.65); }
.status-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.status-summary div { display: flex; align-items: baseline; gap: 9px; padding: 16px 18px; border-radius: 15px; background: rgba(255,255,255,.62); border: 1px solid rgba(255,255,255,.86); }
.status-summary strong { font: 700 26px Georgia, serif; }
.status-summary span { color: var(--muted); font-size: 12px; }
.context-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.context-summary div { display: flex; align-items: baseline; gap: 9px; padding: 16px 18px; border-radius: 15px; background: rgba(255,255,255,.62); border: 1px solid rgba(255,255,255,.86); }
.context-summary strong { font: 700 26px Georgia, serif; }
.context-summary span { color: var(--muted); font-size: 12px; }
.table-card { overflow: hidden; background: var(--paper); border: 1px solid rgba(255,255,255,.88); border-radius: 20px; box-shadow: var(--shadow); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 700px; }
.context-table { min-width: 1040px; }
th { color: var(--muted); font-size: 11px; letter-spacing: .07em; text-transform: uppercase; text-align: left; background: rgba(217,232,223,.28); }
th, td { padding: 15px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .15s; }
tbody tr:hover { background: rgba(217,232,223,.26); }
tbody tr:last-child td { border-bottom: 0; }
.ticket-cell { display: grid; gap: 4px; max-width: 390px; }
.ticket-cell strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-cell small, td time { color: var(--muted); font-size: 11px; }
.status-pill { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-submitted { background: #fff0cb; color: #7c5b16; }
.status-analyzing { background: #dceafa; color: #285a8d; }
.status-analyzed { background: #dbeedf; color: #24613a; }
.status-needs_info { background: #f9e0db; color: #8a392e; }
.status-closed { background: #e6e8e7; color: #54605c; }
.audit-status-ready { background: #dbeedf; color: #24613a; }
.audit-status-auditing { background: #dceafa; color: #285a8d; }
.audit-status-pending { background: #fff0cb; color: #7c5b16; }
.audit-status-stale, .audit-status-error { background: #f9e0db; color: #8a392e; }
.coverage-status-complete, .coverage-item-verified { background: #dbeedf; color: #24613a; }
.coverage-status-partial, .coverage-item-missing { background: #fff0cb; color: #7c5b16; }
.coverage-status-needs_review, .coverage-item-needs_review { background: #f9e0db; color: #8a392e; }
.coverage-item-not_applicable { background: #e6e8e7; color: #54605c; }
.coverage-gap-count { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.open-button { border: 0; background: transparent; color: var(--green-2); cursor: pointer; font-weight: 800; }
.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }

.issue-dialog { width: min(720px, calc(100% - 28px)); max-height: 88vh; padding: 0; border: 0; border-radius: 22px; color: var(--ink); box-shadow: 0 30px 90px rgba(20,35,31,.28); }
.issue-dialog::backdrop { background: rgba(20,35,31,.55); backdrop-filter: blur(3px); }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; padding: 24px 26px 18px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font: 700 25px/1.2 Georgia, serif; }
.dialog-content { padding: 24px 26px 30px; overflow-y: auto; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.detail-box { padding: 13px 14px; border-radius: 12px; background: #f4f6f4; }
.detail-box span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.detail-copy { white-space: pre-wrap; line-height: 1.7; }
.detail-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 18px 0; }
.detail-images img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 11px; border: 1px solid var(--line); }
.analysis-card { margin-top: 22px; padding: 18px; border-radius: 14px; background: #edf5f0; border-left: 4px solid var(--green-2); }
.analysis-card h3 { margin: 0 0 10px; }
.finding { margin-top: 12px; padding-top: 12px; border-top: 1px solid #cdded3; }
.finding code { display: block; margin: 5px 0; color: #254e42; overflow-wrap: anywhere; }
.context-dialog { width: min(940px, calc(100% - 28px)); }
.context-detail-grid { grid-template-columns: repeat(4, 1fr); }
.context-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.context-section h3 { margin: 0 0 12px; font-size: 15px; }
.context-section-error { color: var(--danger); }
.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.source-card { display: grid; gap: 6px; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: #f7f9f7; }
.source-card span, .source-card small { color: var(--muted); font-size: 11px; }
.source-card code { color: #254e42; font-size: 11px; overflow-wrap: anywhere; }
.context-object-list { display: grid; gap: 7px; margin: 0; padding-left: 21px; color: #254e42; font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; }
.coverage-list, .gap-list { display: grid; gap: 9px; }
.coverage-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: #f7f9f7; }
.coverage-copy { display: grid; gap: 3px; }
.coverage-copy small { color: var(--muted); line-height: 1.45; }
.gap-card { padding: 12px 14px; border-left: 3px solid var(--gold); border-radius: 10px; background: #fff7e3; }
.gap-card p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.gap-card code { display: block; margin-top: 7px; color: #7c5b16; font-size: 11px; overflow-wrap: anywhere; }
.audit-timeline, .audit-log-list { display: grid; gap: 9px; }
.audit-event { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 14px; border-left: 3px solid var(--line); border-radius: 10px; background: #f7f9f7; }
.audit-event-ready { border-left-color: #4f9a68; }
.audit-event-running { border-left-color: #4d83b7; }
.audit-event-error { border-left-color: var(--danger); }
.audit-event span { color: var(--muted); font-size: 11px; text-align: right; }
.audit-event p { grid-column: 1 / -1; margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.audit-change { grid-column: 1 / -1; padding: 7px 9px; border-radius: 7px; background: #e8f1eb; color: #254e42; line-height: 1.45; }
.audit-log { display: grid; grid-template-columns: 150px 130px 1fr; gap: 12px; align-items: baseline; padding: 9px 11px; border-radius: 9px; background: #f7f9f7; font-size: 12px; }
.audit-log time { color: var(--muted); }
.audit-log-warning { background: #fff7e3; }
.audit-log-error { background: #fbebe8; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: 360px; padding: 13px 17px; border-radius: 12px; background: var(--green); color: #fff; box-shadow: var(--shadow); }

@media (max-width: 720px) {
  .topbar { height: auto; min-height: 66px; padding: 10px 14px; grid-template-columns: auto 1fr auto; gap: 10px; }
  .brand span:last-child, .user-name { display: none; }
  .primary-nav { grid-column: 1 / -1; grid-row: 2; width: 100%; justify-self: center; }
  .nav-button { flex: 1; padding: 8px 10px; font-size: 12px; white-space: nowrap; }
  .content-shell { width: min(100% - 24px, 950px); padding-top: 38px; }
  .issue-form { padding: 20px; border-radius: 19px; }
  .history-heading { align-items: start; flex-direction: column; }
  .status-summary { gap: 7px; }
  .status-summary div { display: grid; gap: 2px; padding: 12px; }
  .context-summary { grid-template-columns: repeat(2, 1fr); gap: 7px; }
  .context-summary div { display: grid; gap: 2px; padding: 12px; }
  .detail-grid { grid-template-columns: 1fr; }
  .audit-log { grid-template-columns: 1fr; gap: 3px; }
  .audit-event { grid-template-columns: 1fr; }
  .audit-event span { text-align: left; }
  .coverage-row { align-items: flex-start; flex-direction: column; }
}
