:root {
    --ww-green: #339966;
    --ww-green-dark: #236b49;
    --ww-green-soft: #ccffcc;
    --ww-input-yellow: #fffde8;
    --ww-blue: #3366ff;
    --ww-text: #222222;
    --ww-muted: #707070;
    --ww-border: #404040;
    --ww-border-light: #d9d9d9;
    --ww-bg: #ffffff;
    --ww-bg-subtle: #f2f2f2;
    --ww-danger: #c62828;
}

* { box-sizing: border-box; }
html { color: var(--ww-text); background: var(--ww-bg-subtle); font-family: "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif; }
body { margin: 0; font-size: 15px; line-height: 1.6; }
a { color: var(--ww-green-dark); }
h1, h2 { line-height: 1.3; }
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0 0 18px; font-size: 20px; }

.app-header { min-height: 64px; display: flex; align-items: center; gap: 34px; padding: 0 32px; color: #fff; background: var(--ww-green-dark); border-bottom: 3px solid var(--ww-green); }
.brand { color: #fff; font-size: 18px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.global-nav { display: flex; gap: 6px; flex: 1; }
.global-nav a { color: #fff; padding: 8px 12px; text-decoration: none; border-radius: 4px; }
.global-nav a:hover { background: rgba(255,255,255,.12); }
.account-area { display: flex; align-items: center; gap: 14px; }
.account-area form { margin: 0; }

.page-shell { width: min(1180px, calc(100% - 48px)); margin: 30px auto 72px; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 30px; background: var(--ww-bg-subtle); border-left: 8px solid var(--ww-green-dark); }
.auth-panel { width: min(480px, 100%); padding: 34px 38px 38px; background: #fff; border: 1px solid var(--ww-border-light); border-top: 5px solid var(--ww-green); border-radius: 5px; }
.auth-panel h1 { margin-bottom: 6px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--ww-border-light); }
.eyebrow { margin: 0 0 4px; color: var(--ww-green-dark); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.muted { color: var(--ww-muted); }

.panel { margin-bottom: 20px; padding: 24px; background: #fff; border: 1px solid var(--ww-border-light); border-radius: 5px; }
.stacked-form { display: grid; gap: 18px; margin-top: 24px; }
.form-section > h2 { padding: 8px 12px; color: var(--ww-green-dark); background: var(--ww-bg-subtle); border-left: 4px solid var(--ww-green); }
.form-grid { display: grid; gap: 18px 22px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 6px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 10px; color: var(--ww-text); background: #fff; border: 1px solid #999; border-radius: 4px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(51,153,102,.25); border-color: var(--ww-green); }
.important-input { background: var(--ww-input-yellow); }
.required { color: var(--ww-danger); font-size: 12px; }
.field-error { color: var(--ww-danger); font-size: 13px; font-weight: 500; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 18px; border: 1px solid transparent; border-radius: 4px; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
.button-primary { color: #fff; background: var(--ww-green); border-color: var(--ww-green); }
.button-primary:hover { background: var(--ww-green-dark); }
.button-secondary { color: var(--ww-green-dark); background: #fff; border-color: var(--ww-green); }
.button-danger { color: #fff; background: var(--ww-danger); border-color: var(--ww-danger); }
.button-small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.sticky-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; padding: 14px 20px; background: rgba(255,255,255,.95); border: 1px solid var(--ww-border-light); }

.alert { margin-bottom: 18px; padding: 12px 15px; border: 1px solid; border-radius: 4px; }
.alert-success { color: #155c39; background: #eaf8f0; border-color: #9acdaf; }
.alert-error { color: #821b1b; background: #fff0f0; border-color: #e1a5a5; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border: 1px solid var(--ww-border-light); }
th { color: #fff; background: var(--ww-green); }
tbody tr:hover { background: #f3fff7; }
.empty-state { padding: 20px; color: var(--ww-muted); text-align: center; background: var(--ww-bg-subtle); }
.table-panel { padding: 0; }
.table-panel table { border: 0; }
.amount { text-align: right; white-space: nowrap; }
.archived-row { color: var(--ww-muted); background: var(--ww-bg-subtle); }
.filter-bar, .filter-panel { margin-bottom: 20px; padding: 18px; background: #fff; border: 1px solid var(--ww-border-light); }
.filter-bar { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; align-items: end; gap: 14px; }
.filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filter-actions { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.checkbox-label input { width: auto; min-height: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.detail-grid > div { display: grid; gap: 4px; align-content: start; }
.detail-grid span { color: var(--ww-muted); font-size: 13px; }
.detail-grid strong { font-size: 16px; }
.detail-grid p { margin: 0; }
.status-row { display: flex; gap: 8px; margin-top: 12px; }
.status-badge { display: inline-flex; align-items: center; width: fit-content; min-height: 26px; padding: 2px 9px; color: #555; background: #eee; border: 1px solid #bbb; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-quoted { color: #236b49; background: #fff; border-color: var(--ww-green); }
.status-negotiating { color: #fff; background: var(--ww-green); border-color: var(--ww-green); }
.status-on_hold { color: #6b4d00; background: #fff3cd; border-color: #d6a600; }
.status-won { color: #fff; background: var(--ww-green-dark); border-color: var(--ww-green-dark); }
.status-lost, .status-cancelled { color: #8b2424; background: #fff0f0; border-color: #c98989; }
.status-work { color: #34495e; background: #edf2f5; border-color: #9aabb8; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { display: grid; gap: 8px; padding: 17px 18px; color: var(--ww-text); background: #fff; border: 1px solid var(--ww-border-light); border-top: 3px solid var(--ww-green); text-decoration: none; }
.kpi:hover { background: #f3fff7; }
.kpi span { color: var(--ww-muted); font-size: 13px; }
.kpi strong { color: var(--ww-green-dark); font-size: 28px; }
.kpi strong small { margin-left: 2px; font-size: 12px; }
.kpi > small { color: var(--ww-muted); }
.log-value { max-width: 520px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 12px; }
.action-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; }
.action-columns h3 { margin-top: 0; font-size: 16px; }
.count-badge { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; color: #fff; background: var(--ww-green); border-radius: 12px; font-size: 12px; }
.compact-list, .activity-list { margin: 0; padding: 0; list-style: none; }
.compact-list li, .activity-list li { display: grid; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--ww-border-light); }
.compact-list small, .activity-list small { color: var(--ww-muted); }
.content-columns { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 20px; }
.compact-form { margin-top: 18px; }
.inline-form { display: inline-flex; margin-bottom: 12px; }
.danger-zone { display: flex; justify-content: space-between; gap: 16px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--ww-border-light); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 18px; }
.revision { color: var(--ww-green-dark); font-size: .65em; font-weight: 600; }
.estimate-header-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-all { grid-column: 1 / -1; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-heading h2 { margin: 0; }
.estimate-items input { min-width: 90px; }
.estimate-items td:nth-child(2) input { min-width: 280px; }
.item-actions { display: flex; gap: 4px; white-space: nowrap; }
.item-actions button { min-height: 32px; padding: 3px 7px; background: #fff; border: 1px solid var(--ww-border-light); cursor: pointer; }
.estimate-summary { max-width: 540px; margin-left: auto; }
.estimate-summary dl { margin: 0; }
.estimate-summary dl > div { display: flex; justify-content: space-between; gap: 30px; padding: 7px 10px; border-bottom: 1px solid var(--ww-border-light); }
.estimate-summary dt, .estimate-summary dd { margin: 0; }
.estimate-summary dd { font-variant-numeric: tabular-nums; font-weight: 700; }
.estimate-summary .grand-total { margin-top: 8px; padding: 12px 10px; color: #fff; background: var(--ww-green-dark); font-size: 18px; border: 0; }
.issue-form { display: flex; justify-content: flex-end; padding: 18px; background: #fff; border: 1px solid var(--ww-green); }
.order-callout, .order-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: center; gap: 24px; border-left: 4px solid var(--ww-green); }
.order-callout > div, .order-summary > div { display: grid; gap: 2px; }
.order-callout span, .order-summary span { color: var(--ww-muted); font-size: 13px; }
.order-callout strong, .order-summary strong { font-size: 18px; }
.order-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.invoice-create-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 18px; background: var(--ww-bg-subtle); }
.spaced-table { margin-top: 22px; }
.inline-payment { display: flex; align-items: center; gap: 6px; }
.inline-payment input { width: 120px; min-height: 32px; }
.inline-date-form { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
.receipt-row + .receipt-row { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--ww-border-light); }
.completion-panel { border-top: 4px solid var(--ww-green); }
button:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 760px) {
    .app-header { align-items: flex-start; flex-wrap: wrap; gap: 10px; padding: 14px 18px; }
    .global-nav { order: 3; flex-basis: 100%; }
    .page-shell { width: min(100% - 24px, 1180px); margin-top: 18px; }
    .two-columns { grid-template-columns: 1fr; }
    .filter-grid, .kpi-grid, .action-columns, .content-columns, .detail-grid { grid-template-columns: 1fr; }
    .estimate-header-grid { grid-template-columns: 1fr; }
    .order-callout, .order-summary, .invoice-create-grid { grid-template-columns: 1fr; }
    .filter-bar { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .auth-panel { padding: 26px 22px; }
}
