/* =========================================================
   GLOBAL SETTINGS
   ========================================================= */

:root {
    color-scheme: light;

    --background: #f4f6f8;
    --surface: #ffffff;
    --surface-secondary: #edf1f5;

    --text: #263445;
    --text-muted: #647386;

    --border: #d5dce4;

    --primary: #243f59;
    --primary-hover: #182f45;

    --success: #247447;
    --success-background: #e8f5ed;

    --warning: #946200;
    --warning-background: #fff5dc;

    --danger: #a52b2b;

    --radius: 9px;

    --shadow: 0 2px 8px rgba(20, 35, 50, 0.07);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 0;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-width: 0;
    background: var(--background);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid #4b91d1;
    outline-offset: 2px;
}

img,
svg {
    max-width: 100%;
}


/* =========================================================
   APP LAYOUT
   ========================================================= */

#app {
    width: 100%;
    min-height: 100vh;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-main {
    width: 100%;
    max-width: 1050px;
    margin: 0 auto;
    padding: 28px 24px 50px;
    flex: 1;
    min-width: 0;
}

.hidden {
    display: none !important;
}


/* =========================================================
   HEADER
   ========================================================= */

.app-header {
    width: 100%;
    background: var(--primary);
    color: #ffffff;
}

.header-inner {
    max-width: 1050px;
    margin: 0 auto;
    padding: 16px 24px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;

    min-width: 0;
}

.header-brand {
    min-width: 0;
}

.header-brand h1 {
    margin: 0;
    font-size: 1.5rem;
    line-height: 1.2;
}

.header-brand p {
    margin: 4px 0 0;
    font-size: 0.9rem;
    opacity: 0.85;
}

.header-inner .secondary-button {
    flex-shrink: 0;
}


/* =========================================================
   HEADINGS
   ========================================================= */

.page-heading {
    margin-bottom: 26px;
}

.page-heading h2 {
    margin: 0 0 8px;
    font-size: 1.65rem;
    line-height: 1.25;
}

.page-heading p {
    margin: 0;
    color: var(--text-muted);
}

h2,
h3,
h4 {
    overflow-wrap: anywhere;
}

h3 {
    margin-top: 0;
}


/* =========================================================
   BUTTONS
   ========================================================= */

.primary-button,
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-height: 43px;
    padding: 10px 17px;

    border-radius: var(--radius);
    border: 1px solid transparent;

    font-weight: 600;
    text-align: center;

    transition:
        background 0.15s ease,
        border-color 0.15s ease;

    max-width: 100%;
    overflow-wrap: anywhere;
}

.primary-button {
    background: var(--primary);
    color: #ffffff;
}

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

.secondary-button {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.secondary-button:hover {
    background: var(--surface-secondary);
}

.icon-button {
    width: 38px;
    height: 38px;
    padding: 0;

    border: 1px solid var(--border);
    border-radius: 50%;

    background: var(--surface);
    color: var(--text);

    font-size: 1.5rem;
    line-height: 1;
}


/* =========================================================
   HOME SCREEN
   ========================================================= */

.home-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;

    margin-bottom: 36px;
}

.home-actions > .primary-button {
    min-width: 190px;
}

.secondary-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
}

.saved-assessments-section {
    margin-top: 30px;
}

.saved-assessments-section > h2 {
    margin-bottom: 16px;
    font-size: 1.3rem;
}

.empty-state {
    padding: 25px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: center;
    background: var(--surface);
}

.record-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.record-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;

    padding: 18px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow);

    min-width: 0;
}

.record-card-content {
    flex: 1;
    min-width: 0;
}

.record-card-content h3 {
    margin: 0 0 5px;
    font-size: 1.1rem;
    overflow-wrap: anywhere;
}

.record-card-content p {
    margin: 3px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.record-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.record-card-actions button {
    min-height: 38px;
    padding: 8px 12px;
}

.record-card-actions .delete-assessment {
    color: var(--danger);
}


/* =========================================================
   SAVE STATUS
   ========================================================= */

.save-status {
    display: inline-block;
    margin-top: 12px;
    padding: 5px 10px;

    background: var(--success-background);
    color: var(--success);

    border-radius: 5px;
    font-size: 0.85rem;
    font-weight: 600;
}


/* =========================================================
   FORM SECTIONS
   ========================================================= */

.form-section {
    margin: 22px 0;
    padding: 22px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow);

    min-width: 0;
}

.form-section h3 {
    margin-bottom: 12px;
    font-size: 1.25rem;
}

.form-section > p {
    color: var(--text-muted);
    margin-top: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    min-width: 0;
}

.form-group {
    width: 100%;
    min-width: 0;
    margin-bottom: 18px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 7px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

input[type="text"],
input[type="date"],
input[type="time"],
textarea,
select {
    display: block;

    width: 100%;
    max-width: 100%;
    min-width: 0;

    padding: 11px 12px;

    border: 1px solid #bdc8d3;
    border-radius: 6px;

    background: #ffffff;
    color: #263445;

    line-height: 1.5;
}

textarea {
    min-height: 90px;
    resize: vertical;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

input::placeholder,
textarea::placeholder {
    color: #7b8794;
    opacity: 1;
}


/* =========================================================
   DOMAIN LIST
   ========================================================= */

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    min-width: 0;
}

.section-heading > div {
    min-width: 0;
}

.section-heading p {
    color: var(--text-muted);
    margin-top: 0;
}

.domain-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;

    min-width: 0;
}

.domain-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;

    width: 100%;
    min-width: 0;
    min-height: 85px;

    padding: 15px;

    border: 1px solid var(--border);
    border-left: 5px solid #a8b3bf;
    border-radius: 7px;

    background: var(--surface);
    color: var(--text);

    text-align: left;

    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.domain-card:hover {
    background: var(--surface-secondary);
}

.domain-card.completed {
    border-left-color: var(--success);
}

.domain-card.incomplete {
    border-left-color: #b4bec8;
}

.domain-name {
    font-weight: 700;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.domain-status {
    color: var(--text-muted);
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}


/* =========================================================
   DOMAIN EDITOR
   ========================================================= */

.domain-editor {
    margin: 22px 0;
    padding: 22px;

    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: var(--radius);

    box-shadow: var(--shadow);

    min-width: 0;
}

.editor-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;

    margin-bottom: 20px;
    min-width: 0;
}

.editor-heading h3 {
    margin: 5px 0;
    font-size: 1.3rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.editor-heading .icon-button {
    flex-shrink: 0;
}

.editor-section {
    margin-bottom: 25px;
    min-width: 0;
}

.editor-section h4 {
    margin: 0 0 12px;
    font-size: 1.05rem;
}

.domain-criteria {
    padding: 15px;

    background: var(--surface-secondary);
    border-radius: 6px;

    min-width: 0;
    overflow-wrap: anywhere;
}

.domain-criteria p {
    margin: 0 0 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.domain-criteria p:last-child {
    margin-bottom: 0;
}

.or-divider,
.and-divider {
    margin: 14px 0 !important;
    font-weight: 700;
    text-align: center;
}

.or-divider {
    color: var(--primary);
}

.and-divider {
    color: var(--text-muted);
}


/* =========================================================
   LEVEL OPTIONS
   ========================================================= */

.level-options {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    min-width: 0;
}

.level-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;

    padding: 10px 13px;

    border: 1px solid var(--border);
    border-radius: 6px;

    background: var(--surface);

    cursor: pointer;
    font-weight: 600;

    min-width: 0;
}

.level-option:hover {
    background: var(--surface-secondary);
}

.level-option.selected {
    border-color: var(--primary);
    background: #e8eef4;
    color: var(--primary);
}

.level-option input {
    margin: 0;
    flex-shrink: 0;
}


/* =========================================================
   EDITOR ACTIONS
   ========================================================= */

.editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}


/* =========================================================
   ASSESSMENT ACTIONS
   ========================================================= */

.assessment-actions {
    margin-bottom: 35px;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
}


/* =========================================================
   SUMMARY
   ========================================================= */

.summary-content {
    min-width: 0;
    overflow-wrap: anywhere;
}

.summary-section {
    margin: 20px 0;
    padding: 22px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow);

    min-width: 0;
}

.summary-section h2 {
    margin-top: 0;
    font-size: 1.35rem;
}

.summary-section h3 {
    margin-top: 0;
    font-size: 1.15rem;
}

.summary-section h4 {
    margin: 16px 0 6px;
    font-size: 1rem;
}

.summary-domain {
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
    min-width: 0;
}

.summary-domain:last-child {
    border-bottom: 0;
}

.summary-domain p {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.summary-evidence,
.summary-comments {
    padding: 12px;
    background: var(--surface-secondary);
    border-radius: 5px;
}

.summary-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 25px 0;
}


/* =========================================================
   NOTIFICATIONS
   ========================================================= */

.notification {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;

    max-width: min(400px, calc(100vw - 40px));

    padding: 14px 18px;

    border-radius: 7px;
    background: var(--primary);
    color: #ffffff;

    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);

    overflow-wrap: anywhere;
}

.notification.hidden {
    display: none !important;
}

.notification.visible {
    display: block;
}


/* =========================================================
   FOOTER
   ========================================================= */

.app-footer {
    padding: 18px 20px;
    text-align: center;

    color: var(--text-muted);
    font-size: 0.85rem;
}

.app-footer p {
    margin: 0;
}


/* =========================================================
   TABLET AND NARROW DESKTOP
   ========================================================= */

@media (max-width: 760px) {

    .app-main {
        padding: 22px 18px 40px;
    }

    .header-inner {
        padding: 14px 18px;
    }

    .domain-list {
        grid-template-columns: 1fr;
    }

    .record-card {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
    }

    .record-card-actions {
        width: 100%;
    }

    .record-card-actions button {
        flex: 1;
    }

}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 520px) {

    body {
        font-size: 15px;
    }

    .app-main {
        padding: 18px 12px 35px;
    }

    .header-inner {
        padding: 12px;
    }

    .header-brand h1 {
        font-size: 1.25rem;
    }

    .header-brand p {
        font-size: 0.8rem;
    }

    .page-heading h2 {
        font-size: 1.4rem;
    }

    .form-section {
        padding: 16px;
        margin: 16px 0;
    }

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

    .domain-editor {
        padding: 16px;
    }

    .domain-card {
        padding: 13px;
    }

    .secondary-actions {
        width: 100%;
        flex-direction: column;
    }

    .secondary-actions button {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons button {
        width: 100%;
    }

    .editor-actions {
        flex-direction: column;
    }

    .editor-actions button {
        width: 100%;
    }

    .summary-actions {
        flex-direction: column;
    }

    .summary-actions button {
        width: 100%;
    }

    .level-options {
        flex-direction: column;
    }

    .level-option {
        width: 100%;
    }

    .record-card-actions {
        flex-direction: column;
    }

    .record-card-actions button {
        width: 100%;
    }

}


/* =========================================================
   VERY NARROW SCREENS
   ========================================================= */

@media (max-width: 350px) {

    .app-main {
        padding-left: 9px;
        padding-right: 9px;
    }

    .form-section,
    .domain-editor,
    .summary-section {
        padding: 12px;
    }

    .header-brand h1 {
        font-size: 1.1rem;
    }

    .primary-button,
    .secondary-button {
        padding: 9px 11px;
        font-size: 0.9rem;
    }

}


/* =========================================================
   PRINT
   ========================================================= */

@media print {

    @page {
        size: A4;
        margin: 15mm;
    }

    body {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 10pt;
    }

    #app {
        display: block;
    }

    .app-header,
    .app-footer,
    .notification,
    .summary-actions,
    #home-screen,
    #assessment-screen {
        display: none !important;
    }

    .app-main {
        display: block;
        width: 100%;
        max-width: none;
        padding: 0;
        margin: 0;
    }

    #summary-screen {
        display: block !important;
    }

    .summary-section {
        box-shadow: none;
        border: 1px solid #cccccc;
        background: #ffffff !important;
        color: #000000 !important;

        padding: 12px;
        margin: 12px 0;

        break-inside: auto;
    }

    .summary-domain {
        break-inside: avoid;
    }

    .summary-evidence,
    .summary-comments {
        background: #f5f5f5 !important;
        color: #000000 !important;
    }

    h2,
    h3,
    h4 {
        break-after: avoid;
    }

    p {
        overflow-wrap: anywhere;
    }

}
