/* Translator Client Profitability — base design system (§35, §36, §48)
   Small custom CSS: clean, calm, trustworthy, spacious, readable, responsive.
   No UI framework. Semantic colors are never the only signal — always paired with text. */

:root {
    --font-stack: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono-stack: "Cascadia Mono", Consolas, "Courier New", monospace;

    --text: #1f2933;
    --text-muted: #52606d;
    --surface: #ffffff;
    --surface-alt: #f5f7fa;
    --border: #d9e2ec;

    --accent: #1d4ed8;
    --accent-hover: #1e40af;

    /* Semantic states (§36) */
    --success: #18794e;
    --success-bg: #e6f4ec;
    --attention: #946200;
    --attention-bg: #fdf3d7;
    --danger: #b42318;
    --danger-bg: #fdecea;

    --radius: 6px;
    --space: 1rem;
}

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: var(--font-stack);
    color: var(--text);
    background: var(--surface-alt);
    line-height: 1.55;
}

.app-loading {
    max-width: 64rem;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    color: var(--text-muted);
}

a {
    color: var(--accent);
}

/* Visible keyboard focus everywhere it was missing (buttons, links, nav). */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius);
}

/* Keep route announcements without outlining non-interactive page headings. */
h1[tabindex="-1"]:focus-visible {
    outline: none;
}

h1 {
    font-size: 1.6rem;
    margin: 0 0 0.75rem;
}

h2 {
    font-size: 1.15rem;
    margin: 0 0 0.5rem;
}

.lede {
    color: var(--text-muted);
    font-size: 1.05rem;
    margin-top: -0.25rem;
}

/* --- Layout --- */

.container {
    max-width: 64rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.site-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
    max-width: 62rem;
    margin-inline: auto;
    padding: 0.5rem 0 1.25rem;
    margin-block: 0 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.site-footer a {
    padding-block: 0.4rem;
    color: inherit;
}

@media (max-width: 64rem) {
    .site-footer {
        margin-inline: 0.75rem;
    }
}

/* --- Top navigation (§34) --- */

.topnav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topnav-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
    max-width: 64rem;
    margin-inline: auto;
    padding: 0.4rem 1rem;
}

.topnav .brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    margin-right: auto;
}

.topnav .brand img {
    display: block;
    height: 34px;
    width: auto;
}

@media (max-width: 40rem) {
    .topnav .brand img {
        height: 28px;
    }
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
}

.nav-links a {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.25rem 0;
    border-bottom: 2px solid transparent;
}

.nav-links a:hover {
    color: var(--text);
}

.nav-links a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.nav-links a.nav-action {
    padding-inline: 0.55rem;
    border-radius: 0.4rem;
    background: var(--accent);
    color: white;
    font-weight: 600;
}

.nav-links a.nav-action.active {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.home-page {
    display: grid;
    gap: 1.5rem;
}

.home-page > section + section {
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
}

.home-page h1 {
    font-size: clamp(1.6rem, 3vw, 2rem);
    line-height: 1.2;
}

.home-page h3 {
    font-size: 1rem;
    margin: 0;
}

.home-page :is(section > p, .insight-list) {
    max-width: 68ch;
}

.home-page p {
    margin: 0 0 0.75rem;
}

.home-page .hint {
    color: var(--text-muted);
}

.home-page :is(p, .insight-list):last-child {
    margin-bottom: 0;
}

.home-page .field-grid {
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.home-page .field-grid .panel {
    display: grid;
    align-content: start;
    gap: 0.5rem;
    margin-top: 0;
}

.home-page .field-grid p {
    margin: 0;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.container:has(.home-page) + .site-footer {
    width: calc(100% - 2rem);
    margin-inline: auto;
}

/* --- Panels, empty states, page header --- */

.panel,
.empty-state {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-top: 1rem;
}

.empty-state {
    color: var(--text-muted);
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.page-header h1 {
    margin: 0;
}

/* --- Buttons --- */

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover {
    background: var(--surface-alt);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn:disabled,
.btn:disabled:hover {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--surface);
}

.btn-primary:disabled,
.btn-primary:disabled:hover {
    background: var(--accent);
}

/* --- Semantic status badges (§36: color + text, never color alone) --- */

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.badge-success {
    color: var(--success);
    background: var(--success-bg);
}

.badge-attention {
    color: var(--attention);
    background: var(--attention-bg);
}

.btn.btn-danger {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: var(--danger);
}

.badge-danger {
    color: var(--danger);
    background: var(--danger-bg);
}

.badge-neutral {
    color: var(--text-muted);
    background: var(--surface-alt);
}

.financial-positive {
    color: var(--success);
}

.financial-adverse,
.stat-label.financial-adverse {
    color: var(--danger);
}

/* --- Tables (preferred over decorative charts, §37) --- */

.table-wrapper {
    overflow-x: auto;
    margin-top: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

table.data th,
table.data td {
    text-align: left;
    padding: 0.6rem 0.65rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data th {
    color: var(--text-muted);
    font-weight: 600;
    background: var(--surface-alt);
}

table.data tr:last-child td {
    border-bottom: none;
}

table.data .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Long text columns (client, project name) wrap instead of forcing
   horizontal scrolling at desktop widths (L4-B). */
table.data td.wrap {
    white-space: normal;
}

/* --- Forms --- */

.field {
    margin-bottom: 1rem;
    max-width: 24rem;
}

.field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.field input,
.field select {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
}

.field input:focus,
.field select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.field .hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.password-control {
    position: relative;
}

.password-control input {
    min-width: 0;
    padding-inline-end: 3rem;
}

.password-toggle {
    position: absolute;
    inset-block: 0.25rem;
    inset-inline-end: 0.25rem;
    width: 2.25rem;
    display: grid;
    place-items: center;
    padding: 0.35rem;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.password-toggle:hover {
    color: var(--accent);
    background: var(--surface-alt);
}

.password-toggle[hidden],
.password-toggle[data-visible="true"] .password-eye,
.password-toggle[data-visible="false"] .password-eye-off {
    display: none;
}

.password-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

.field input.invalid,
.field select.invalid {
    border-color: var(--danger);
}

/* --- Project form + live preview (L3) --- */

.form-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 19rem;
    gap: 1rem;
    margin-top: 1rem;
    align-items: start;
}

.form-layout .panel {
    margin-top: 0;
}

.form-layout h2 {
    margin-top: 1.5rem;
}

.form-layout h2:first-child {
    margin-top: 0;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    column-gap: 1rem;
}

.choice-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin-bottom: 1rem;
}

.choice {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    cursor: pointer;
}

.choice input {
    margin: 0;
    accent-color: var(--accent);
}

.choice input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius);
}

.secondary-heading {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 1.5rem;
}

.hint-inline {
    font-weight: 400;
}

.preview {
    position: sticky;
    top: 1rem;
}

.preview-list {
    margin: 0;
}

.preview-list > div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}

.preview-list > div:last-child {
    border-bottom: none;
}

.preview-list dt {
    color: var(--text-muted);
    flex: 1 1 auto;
    min-width: 0;
    padding-right: 0.5rem;
}

.preview-list dd {
    margin: 0;
    flex: 0 0 auto;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.preview-secondary {
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

.validation-message,
.field-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.notice-success {
    background: var(--success-bg);
    color: var(--success);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    margin-top: 0.75rem;
    font-size: 0.95rem;
}

/* Page-level feedback messages get the same calm block style as success. */
p.field-error[role="alert"] {
    background: var(--danger-bg);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
}

.restore-file-name {
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* --- Blazor error UI --- */

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1rem;
    background: var(--danger-bg);
    color: var(--danger);
    border-top: 1px solid var(--danger);
    z-index: 1000;
}

#blazor-error-ui .reload {
    color: var(--danger);
    font-weight: 600;
    margin-left: 0.5rem;
}

/* --- Responsive (§35: desktop and mobile) --- */

@media (max-width: 40rem) {
    .container {
        padding: 1rem 0.75rem 2.5rem;
    }

    .container:has(.home-page) + .site-footer {
        width: calc(100% - 1.5rem);
    }

    .nav-links {
        gap: 0.25rem 0.75rem;
        font-size: 0.95rem;
    }

    .form-layout {
        grid-template-columns: 1fr;
    }

    .preview {
        position: static;
    }
}

/* --- Project history actions (L4-B) --- */

.link-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--accent);
    text-decoration: underline;
    cursor: pointer;
}

.link-btn.danger {
    color: var(--danger);
}

.row-actions {
    white-space: nowrap;
}

.row-actions > * + * {
    margin-left: 0.5rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* --- Search / filter bar (L4-C) --- */

.project-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    margin-block: 1rem;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0 1rem;
    margin-top: 1rem;
}

.filter-bar .field {
    flex: 1 1 11rem;
    max-width: 18rem;
    margin-bottom: 0.75rem;
}

.filter-bar .btn {
    margin-bottom: 0.75rem;
}

/* --- Client comparison insights (L5-B) --- */

.insight-panel {
    margin-top: 1rem;
}

.insight-list {
    margin: 0;
    padding-left: 1.25rem;
}

.insight-list li + li {
    margin-top: 0.25rem;
}

.insight-panel .hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0.5rem 0 0;
}

/* --- Dashboard overview metrics (L6-A) --- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

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

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
}

.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* --- First-time guidance and metric help (P1.5) --- */

.how-it-works {
    border-top: 1px solid var(--border);
    margin-top: 1.25rem;
    padding-top: 1rem;
    text-align: left;
}

.how-it-works h3 {
    font-size: 1rem;
    margin: 0 0 0.5rem;
}

.how-it-works ol {
    margin: 0;
    padding-left: 1.25rem;
}

.how-it-works li + li {
    margin-top: 0.25rem;
}

.how-it-works .hint {
    font-size: 0.85rem;
    margin: 0.75rem 0 0;
}

.metric-help {
    margin: 0;
}

.metric-help dt {
    font-weight: 600;
    margin-top: 0.75rem;
}

.metric-help dt:first-child {
    margin-top: 0;
}

.metric-help dd {
    margin: 0.15rem 0 0;
    color: var(--text-muted);
}

/* Account and profitability emphasis */
.google-sign-in {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #747775;
  border-radius: 6px;
  background: #fff;
  color: #1f1f1f;
  font: 500 14px/20px "Google Sans", Arial, sans-serif;
  cursor: pointer;
}

.google-sign-in:hover {
  background: #f8faff;
}

.google-sign-in img {
  flex: none;
}

.account-container {
    max-width: 34rem;
}

.nav-account {
    position: relative;
}

.nav-account summary {
    cursor: pointer;
    padding: 0.6rem 0.4rem;
}

.nav-account:has(a.active) summary {
    color: var(--accent);
    font-weight: 600;
}

.account-links {
    position: absolute;
    z-index: 2;
    inset-inline-end: 0;
    width: min(18rem, calc(100vw - 2rem));
    display: grid;
    gap: 0;
    padding: 0.65rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 6px 18px rgb(0 0 0 / 12%);
}

.account-email {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0;
    overflow-wrap: anywhere;
}

.preview-list > .key-result {
    background: var(--surface);
    padding-inline: 0.5rem;
}

.preview-list .key-result dd {
    font-size: 1.15rem;
    font-weight: 700;
}

.currency-highlights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

@media (max-width: 40rem) {
    .topnav-inner {
        gap: 0.15rem 0.75rem;
        padding: 0.25rem 0.75rem;
    }

    .work-nav {
        order: 1;
        flex-basis: 100%;
        font-size: 0.875rem;
    }

    .nav-links {
        gap: 0 0.5rem;
    }

    .nav-account {
        font-size: 0.875rem;
    }

    table.project-history {
        table-layout: fixed;
    }

    table.project-history .history-secondary {
        display: none;
    }

    table.project-history :is(th, td) {
        padding-inline: 0.3rem;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    table.project-history .row-actions > * {
        display: block;
        margin: 0;
        padding: 0.25rem 0;
    }
}
