:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #1d4f91;
    --primary-dark: #163d70;
    --secondary: #e8eef5;
    --danger: #b42318;
    --success: #067647;
    --border: #d7dee7;
    --radius: 14px;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 18px;
    line-height: 1.5;
}

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

.app-shell {
    min-height: 100vh;
}

.app-header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
}

.app-main {
    max-width: 980px;
    margin: 0 auto;
    padding: 1.25rem;
}

.page-title {
    margin: 0 0 0.5rem;
    font-size: 1.8rem;
}

.page-subtitle {
    margin: 0 0 1.25rem;
    color: var(--muted);
}

.page-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.page-top .page-title {
    flex: 1;
}

.card, .fieldset {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card {
    padding: 1.25rem;
}

.card-narrow {
    max-width: 560px;
    margin: 2rem auto;
}

.fieldset {
    padding: 1rem;
    margin-bottom: 1rem;
    border: none;
}

.fieldset legend {
    font-weight: 700;
    padding: 0 0.25rem;
    margin-bottom: 0.75rem;
}

.form-grid {
    display: grid;
    gap: 0.75rem;
}

.field {
    display: grid;
    gap: 0.35rem;
}

.field span {
    font-size: 0.95rem;
    color: var(--muted);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 2px solid rgba(29, 79, 145, 0.25);
    border-color: var(--primary);
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.checkbox-field input {
    width: 1.2rem;
    height: 1.2rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    border-radius: 12px;
    padding: 0.85rem 1.1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
    text-align: center;
}

.btn:active {
    transform: scale(0.98);
}

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

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

.btn-secondary {
    background: var(--secondary);
    color: var(--text);
}

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

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

.btn-large {
    padding: 1.1rem 1.25rem;
    font-size: 1.1rem;
}

.btn-huge {
    width: 100%;
    min-height: 84px;
    font-size: 1.35rem;
    border-radius: 16px;
}

.btn-small {
    padding: 0.55rem 0.8rem;
    font-size: 0.9rem;
}

.big-buttons {
    display: grid;
    gap: 1rem;
    margin-top: 1.5rem;
}

.alert {
    border-radius: 12px;
    padding: 0.9rem 1rem;
    margin-bottom: 1rem;
}

.alert p {
    margin: 0.25rem 0;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecdca;
}

.alert-success {
    background: #ecfdf3;
    color: var(--success);
    border: 1px solid #abefc6;
}

.hidden {
    display: none !important;
}

.type-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.type-btn {
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    background: #fff;
}

.type-btn input {
    display: none;
}

.type-btn.active {
    border-color: var(--primary);
    background: #eef4fb;
    color: var(--primary);
    font-weight: 700;
}

.item-row {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: #fafbfc;
}

.item-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.25rem;
}

.item-actions .btn {
    width: 100%;
    min-height: 52px;
}

.item-actions .hint {
    margin-top: 0;
    text-align: center;
}

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

.totals-box .totals {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.75rem;
    font-size: 1.05rem;
}

.total-line {
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-size: 1.2rem;
}

.action-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
}

.doc-cards {
    display: grid;
    gap: 1rem;
}

.doc-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.doc-card h2 {
    margin: 0.4rem 0;
    font-size: 1.3rem;
}

.doc-meta {
    margin: 0.2rem 0;
    color: var(--muted);
}

.doc-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badge {
    background: #eef4fb;
    color: var(--primary);
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
}

.status {
    font-size: 0.85rem;
    font-weight: 700;
}

.status-final {
    color: var(--success);
}

.status-draft {
    color: var(--muted);
}

.page-title {
    margin: 0;
}

.page-subtitle {
    margin: 0.25rem 0 0;
    text-align: center;
}

.doc-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.inline-form {
    display: inline;
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.logo-preview img {
    max-width: 180px;
    max-height: 100px;
    object-fit: contain;
    margin-bottom: 0.75rem;
}

.pin-change-card {
    margin-top: 1.5rem;
}

.hint {
    margin-top: 0.75rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.hint-success {
    color: var(--success);
}

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

.field-with-ai {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.field-with-ai .ai-improve-btn {
    align-self: stretch;
    width: 100%;
    min-height: 48px;
}

.ai-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.ai-modal.hidden {
    display: none;
}

.ai-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.ai-modal-card {
    position: relative;
    width: min(640px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.ai-modal-title {
    margin: 0 0 0.35rem;
    font-size: 1.45rem;
}

.ai-modal-subtitle {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 1rem;
}

.ai-wait-icon {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.ai-wait-hint {
    text-align: center;
    font-weight: 600;
}

.ai-step-label {
    margin: 0 0 0.35rem;
    font-weight: 700;
    font-size: 1rem;
}

.ai-step-label-new {
    margin-top: 0.85rem;
    color: var(--primary);
}

.ai-modal-status {
    font-size: 1.1rem;
    margin: 0 0 1rem;
    text-align: center;
}

.ai-progress-track {
    height: 12px;
    background: var(--secondary);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.ai-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #3b82f6);
    border-radius: 999px;
    transition: width 0.35s ease;
}

.ai-compare {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.ai-compare-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem;
    max-height: 9rem;
    overflow-y: auto;
}

.ai-compare-box h3 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    color: var(--muted);
}

.ai-compare-box p {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-compare-new {
    border-color: var(--primary);
    background: #f0f6ff;
}

.ai-feedback-block {
    margin-bottom: 1rem;
}

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

.ai-modal-actions .btn-large {
    flex: 1 1 100%;
}

.ai-modal-result.hidden,
.ai-modal-loading.hidden,
.ai-modal-bulk.hidden {
    display: none;
}

.btn-huge {
    min-height: 68px;
    font-size: 1.2rem;
    font-weight: 700;
    width: 100%;
}

.ai-improve-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.input-pin {
    font-size: 2rem !important;
    letter-spacing: 0.5rem;
    text-align: center;
}

.page-login .app-main,
.page-install .app-main {
    display: flex;
    align-items: center;
    min-height: calc(100vh - 2rem);
}

.action-bar-single {
    grid-template-columns: 1fr;
}

.action-bar-single .btn-large {
    min-height: 64px;
    font-size: 1.25rem;
}

.app-version-hint {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

.mobile-toast {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1.25rem;
    z-index: 9999;
    background: #1f2937;
    color: #fff;
    padding: 1rem 1.1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.45;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.mobile-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 768px) {
    .grid-2, .grid-3, .type-buttons, .action-bar {
        grid-template-columns: 1fr;
    }

    .app-main {
        padding: 1rem;
    }

    .page-title {
        font-size: 1.5rem;
    }
}

@media (min-width: 769px) {
    .dashboard .big-buttons {
        max-width: 520px;
        margin-left: auto;
        margin-right: auto;
    }
}
