:root {
    --brand-blue: #182339;
    --brand-blue-light: #00A3dA;
    --brand-slate: #0f172a;
    --brand-ice: #f2f6fb;
    --text-body: #0f172a;
    --text-muted: #5f6c7b;
    --border: rgba(11, 52, 85, 0.15);
    --success: #2e8540;
    --danger: #b91c1c;
    font-family: 'Titillium Web', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--brand-ice);
    color: var(--text-body);
    font-family: 'Titillium Web', sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.5rem;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    font-size: 0.95rem;
}

.btn.primary {
    background: var(--brand-blue-light);
    color: #fff;
    box-shadow: 0 8px 20px rgba(11, 52, 85, 0.25);
}

.btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(11, 52, 85, 0.3);
}

.btn.ghost {
    background: transparent;
    border: 1px solid var(--brand-blue);
    color: var(--brand-blue);
}

.btn.danger {
    background: var(--danger);
    color: #fff;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, rgba(11, 52, 85, 0.2), transparent 70%), var(--brand-ice);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
}

.auth-card {
    background: var(--brand-blue);
    border-radius: 24px;
    padding: 2.5rem 2rem;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
    max-width: 100%;
    overflow: hidden;
}

.auth-header img {
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1.75rem;
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.auth-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.auth-form input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.auth-container h1,p {
    color: var(--brand-ice)
}

.form-feedback {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.form-feedback.error {
    color: var(--danger);
}

.form-feedback.success {
    color: var(--success);
}

.app-header {
    background: #182339;
    padding: 1rem 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.05);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.brand-banner {
    width: auto;
    height: 100px;
    overflow: hidden;
    flex: 0 0 auto;
}

.brand-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.brand-meta h1 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--brand-ice);
}

.brand-meta p {
    margin: 0.25rem 0 0;
    color: white;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-actions form {
    margin: 0;
}

.app-shell {
    padding: 2rem 2.5rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.app-shell.narrow {
    max-width: 860px;
    margin: 0 auto;
}

.panel {
    background: #fff;
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.05);
}

.panel.two-column {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
}

.panel h2 {
    margin-top: 0;
    font-size: 1.4rem;
}

.field {
    margin-bottom: 1.5rem;
}

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

.input,
.field input,
.field select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-size: 1rem;
    font-family: inherit;
}

.inline-inputs {
    display: flex;
    gap: 0.75rem;
}

.inline-inputs input {
    flex: 1;
}

.inline-inputs button {
    flex: 0 0 auto;
}

.upload-card {
    background: #f8fbff;
    border: 1px dashed rgba(11, 52, 85, 0.2);
    border-radius: 20px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.drop-zone {
    border: 2px dashed rgba(11, 52, 85, 0.4);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}
.drop-zone p {
    color:  var(--brand-slate);
}

.drop-zone.dragover {
    border-color: var(--brand-blue);
    background: rgba(11, 52, 85, 0.05);
}

.helper {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.link {
    color: var(--brand-blue);
    font-weight: 600;
    cursor: pointer;
}

.signature-upload {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.current-signature img {
    max-width: 240px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.table-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.table-container {
    max-height: 520px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 16px;
}

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

th, td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(15, 23, 42, 0.05);
}

tr:hover {
    background: rgba(11, 52, 85, 0.04);
}

.editable-cell {
    cursor: text;
    transition: background 0.15s ease;
}

.editable-cell:hover {
    background: rgba(0, 163, 218, 0.08);
}

.editable-cell.editing {
    padding: 0;
    background: rgba(0, 163, 218, 0.12);
}

.editable-cell.saving {
    background: rgba(24, 35, 57, 0.08);
}

.table-inline-input {
    width: 100%;
    padding: 0.85rem 1rem;
    border: none;
    background: transparent;
    font: inherit;
    color: inherit;
    outline: none;
}

.table-inline-input::placeholder {
    color: var(--text-muted);
}

.table-inline-input:focus {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 0 0 2px rgba(0, 163, 218, 0.35);
}


#projectSelect[data-editing="true"] {
    display: none;
}

.select-inline-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-size: 1rem;
    font-family: inherit;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.select-inline-input:focus {
    outline: none;
    border-color: rgba(0, 163, 218, 0.6);
    box-shadow: 0 0 0 3px rgba(0, 163, 218, 0.15);
}

.field.project-rename-active {
    position: relative;
}

.field.project-rename-active .select-inline-input {
    box-shadow: 0 0 0 3px rgba(0, 163, 218, 0.12);
}

.field.project-rename-saving .select-inline-input {
    cursor: progress;
    opacity: 0.85;
}

.project-fields-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-start;
}

.project-field {
    flex: 1 1 320px;
}

.project-select-field {
    min-width: 320px;
}

.job-number-field {
    flex: 0 1 220px;
    max-width: 260px;
}

.project-select-control {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.project-select-control .input {
    flex: 1;
}

.project-delete-note {
    margin-top: 0.5rem;
    font-size: 0.82rem;
}


.settings-shell {
    max-width: 1080px;
    margin: 0 auto;
}

.letter-settings {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

.letter-settings-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
}

.letter-settings-header .helper {
    margin-top: 0.75rem;
    max-width: 640px;
}

.letter-editor {
    display: flex;
    justify-content: center;
}

.letter-page {
    width: 100%;
    max-width: 820px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}

.letter-header-image {
    display: block;
    width: 100%;
    height: auto;
}

.letter-content {
    padding: 60px;
    font-size: 0.95rem;
    line-height: 1.65;
}

.letter-content p {
    margin: 0 0 16px;
}

.letter-date {
    font-size: 0.85rem;
    letter-spacing: 0.01em;
    margin-bottom: 24px;
    color: var(--text-body);
}

.letter-address {
    margin-bottom: 24px;
    color: var(--text-body);
}

.letter-address p {
    margin: 0;
    line-height: 1.5;
    color: var(--text-body);
}

.letter-greeting {
    margin-bottom: 24px;
    color: var(--text-body);
}

.letter-contract {
    font-weight: 700;
    font-size: 1.05rem;
    text-transform: none;
    margin-bottom: 24px;
    color: var(--text-body);
}

.letter-intro {
    margin-bottom: 24px;
    color: var(--text-body);
}

.letter-body-editor {
    min-height: 220px;
    margin-bottom: 24px;
    white-space: pre-wrap;
    outline: none;
    cursor: text;
}

.letter-body-editor:focus {
    box-shadow: inset 0 0 0 2px rgba(0, 163, 218, 0.45);
}

.letter-body-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    opacity: 0.7;
}

.email-settings {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.email-settings h3 {
    margin: 0;
    font-size: 1.2rem;
}

.email-settings label {
    font-weight: 600;
}

.email-settings input,
.email-settings textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
}

.email-settings textarea {
    min-height: 150px;
}

.letter-signoff p {
    margin: 0 0 16px;
    color: var(--text-body);
}

.letter-signature {
    height: 60px;
    display: flex;
    align-items: flex-end;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    color: var(--text-body);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .nav-actions {
        align-self: stretch;
        justify-content: space-between;
        width: 100%;
    }

    .inline-inputs {
        flex-direction: column;
    }

    .email-settings {
        margin-top: 2rem;
        padding-top: 1.5rem;
    }

    .project-fields-row {
        flex-direction: column;
        align-items: stretch;
    }

    .job-number-field {
        max-width: none;
        flex: 1 1 auto;
    }

    .letter-content {
        padding: 36px;
    }

    .letter-settings-header {
        flex-direction: column;
        align-items: stretch;
    }

    .letter-editor {
        justify-content: flex-start;
    }
}

#lettersTable tbody tr.focused {
    outline: 2px solid rgba(11, 52, 85, 0.35);
    outline-offset: -2px;
    background: rgba(11, 52, 85, 0.08);
}

#lettersTable {
    text-align: left;
}

.status-pill {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    display: inline-block;
}

.status-pill.sent {
    background-color: #28a745;
}

.status-pill.not-sent {
    background-color: #dc3545;
}

.status .status-select {
    visibility: hidden;
    width: 0;
    transition: all 0.2s ease-in-out;
    margin-left: 8px;
}

.status:hover .status-select {
    visibility: visible;
    width: auto;
}
