@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

:root {
    --ink: #18231f;
    --muted: #68736e;
    --surface: #ffffff;
    --canvas: #f4f6f1;
    --line: #dfe5de;
    --green: #166b4c;
    --green-dark: #0e5139;
    --mint: #dff3e7;
    --amber: #f2a93b;
    --red: #a63c3c;
    font-family: "DM Sans", sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: "Manrope", sans-serif; letter-spacing: -.035em; }
h1 { margin-bottom: .35rem; font-size: clamp(1.6rem, 3vw, 2.35rem); }
h2 { margin-bottom: 0; font-size: clamp(1.25rem, 2vw, 1.65rem); }

.app-shell { width: min(1440px, 100%); margin: auto; padding: 24px clamp(16px, 3vw, 44px) 64px; }
.topbar, .conversation-strip, .section-heading, .generate-row, .response-head, .top-actions {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar { margin-bottom: 22px; }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: .72rem; font-weight: 800; letter-spacing: .15em; }
.muted { color: var(--muted); }

.conversation-strip, .workspace-card, .response-card, .history-section, .stats-grid article {
    background: var(--surface); border: 1px solid var(--line); box-shadow: 0 10px 35px rgba(30, 50, 40, .055);
}
.conversation-strip { border-radius: 18px; padding: 16px 18px; margin-bottom: 18px; }
.conversation-id { min-width: 250px; }
.conversation-id span, .response-head span, .response-card footer, .stats-grid span { color: var(--muted); font-size: .78rem; }
.conversation-id strong { display: block; margin-top: 4px; font-size: .84rem; overflow-wrap: anywhere; }
.action-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.btn, .copy-button, .icon-button {
    border: 0; border-radius: 11px; cursor: pointer; font-weight: 700; transition: .18s ease;
}
.btn { min-height: 44px; padding: 10px 16px; }
.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(.98); }
.btn:disabled { cursor: not-allowed; opacity: .45; }
.primary { color: #fff; background: var(--green); }
.primary:hover:not(:disabled) { background: var(--green-dark); }
.secondary { color: var(--green-dark); background: var(--mint); }
.danger { color: var(--red); background: #fbe9e7; }
.ghost { color: var(--ink); background: #edf0eb; }
.compact { min-height: 38px; padding: 7px 12px; }
.wide { width: 100%; margin-top: 12px; }

.license-pill, .active-dot { border-radius: 999px; padding: 8px 12px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.license-pill.ok, .active-dot { color: var(--green-dark); background: var(--mint); }
.license-pill.bad { color: var(--red); background: #fbe9e7; }
.active-dot::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #2e9b6e; }

.workspace-card, .history-section { border-radius: 22px; padding: clamp(18px, 3vw, 28px); margin-bottom: 18px; }
.section-heading { margin-bottom: 16px; }
.message-input {
    display: block; width: 100%; min-height: 128px; resize: vertical; border: 1px solid var(--line); border-radius: 14px;
    padding: 15px 16px; color: var(--ink); background: #fbfcfa; outline: none;
}
.message-input:focus, .field:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 107, 76, .11); }
.generate-row { margin-top: 14px; }
.generate { min-width: 210px; }

.response-grid { display: grid; grid-template-columns: 1fr; gap: 18px; margin-bottom: 18px; }
.response-grid.dual { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.response-card { border-radius: 22px; overflow: hidden; min-height: 250px; padding: clamp(18px, 3vw, 26px); display: flex; flex-direction: column; }
.response-card.accent { border-top: 4px solid var(--amber); }
.response-head { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.response-head strong { display: block; margin-top: 4px; }
.output-box {
    flex: 1; width: 100%; min-height: 170px; margin: 16px 0; padding: 14px; resize: vertical;
    border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #fbfcfa;
    line-height: 1.6; white-space: pre-wrap;
}
.response-card.failed { border-color: #e7b6b2; }
.response-card.failed .output-box { color: #792d2d; background: #fff5f4; }
.response-card footer { display: flex; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.copy-button { padding: 7px 11px; color: var(--green); background: var(--mint); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.stats-grid article { border-radius: 15px; padding: 15px; }
.stats-grid strong { display: block; margin-top: 6px; font-family: "Manrope"; }
.history-list { display: grid; gap: 10px; max-height: 480px; overflow: auto; }
.history-list article { padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfa; }
.history-list article > div { display: flex; justify-content: space-between; }
.history-list time { color: var(--muted); font-size: .8rem; }
.history-list p { margin: 8px 0 0; line-height: 1.45; }
.history-list .client-line { color: var(--muted); font-size: .86rem; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 18px; background: radial-gradient(circle at 25% 15%, #dff3e7, transparent 32%), var(--canvas); }
.auth-card { width: min(460px, 100%); padding: clamp(25px, 5vw, 42px); border: 1px solid var(--line); border-radius: 26px; background: rgba(255,255,255,.94); box-shadow: 0 30px 80px rgba(25, 50, 38, .12); }
.brand-mark { display: grid; place-items: center; width: 50px; height: 50px; margin-bottom: 24px; border-radius: 14px; color: #fff; background: var(--green); font-family: "Manrope"; font-weight: 800; }
label { display: block; margin: 13px 0 6px; font-size: .84rem; font-weight: 700; }
.field { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; outline: none; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.code-field { text-align: center; font-size: 1.3rem; letter-spacing: .28em; }
.notice, .error-box, .success-box { border-radius: 12px; padding: 12px 14px; }
.notice { background: #f0f3ee; }
.error-box { color: #792d2d; background: #fbe9e7; }
.success-box { color: var(--green-dark); background: var(--mint); }
.auth-card .error-box { margin-top: 14px; }
.auth-notice { margin-top: 14px; }
.auth-link {
    display: block; width: 100%; margin-top: 14px; padding: 4px; border: 0; color: var(--green);
    background: transparent; cursor: pointer; font-weight: 700; text-align: center; text-decoration: underline;
}
.auth-link:hover { color: var(--green-dark); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(430px, calc(100vw - 40px)); box-shadow: 0 10px 30px rgba(0,0,0,.12); }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(18, 30, 25, .58); backdrop-filter: blur(4px); }
.settings-modal { width: min(780px, 100%); max-height: calc(100vh - 36px); overflow: auto; padding: clamp(20px, 4vw, 30px); border-radius: 24px; background: var(--surface); box-shadow: 0 30px 100px rgba(0,0,0,.25); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.icon-button { width: 38px; height: 38px; font-size: 1.5rem; color: var(--muted); background: #edf0eb; }

@media (max-width: 850px) {
    .topbar, .conversation-strip { align-items: stretch; flex-direction: column; }
    .top-actions { justify-content: space-between; }
    .action-row { display: grid; grid-template-columns: repeat(2, 1fr); }
    .action-row .btn { width: 100%; }
    .response-grid.dual { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
    .app-shell { padding: 16px 12px 48px; }
    .topbar { margin-bottom: 14px; }
    .conversation-strip, .workspace-card, .history-section, .response-card { border-radius: 16px; }
    .action-row, .settings-grid { grid-template-columns: 1fr; }
    .generate-row { align-items: stretch; flex-direction: column; }
    .generate { width: 100%; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .section-heading { align-items: flex-start; }
    .active-dot { display: none; }
    .modal-backdrop { padding: 0; align-items: end; }
    .settings-modal { width: 100%; max-height: 92vh; border-radius: 22px 22px 0 0; }
    .toast { right: 12px; bottom: 12px; max-width: calc(100vw - 24px); }
}

.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; }
