
/* =================================
   HANDYAI - MAIN DESIGN
================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #090b12;
    --surface: #111520;
    --surface-light: #191f2e;
    --border: #292f40;
    --primary: #925cff;
    --primary-hover: #ad83ff;
    --text: #f4f5fa;
    --muted: #9ba3b5;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, sans-serif;
}

/* HEADER */

.header {
    height: 75px;
    padding: 0 8%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: rgba(9, 11, 18, 0.95);
}

.logo {
    color: white;
    font-size: 25px;
    font-weight: 800;
    text-decoration: none;
}

.logo span {
    color: var(--primary);
}

.back-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

.back-link:hover {
    color: white;
}

/* MAIN APP */

.app {
    width: min(900px, 92%);
    margin: 55px auto;
}

/* WELCOME */

.welcome {
    text-align: center;
    margin-bottom: 35px;
}

.ai-icon {
    width: 65px;
    height: 65px;
    margin: 0 auto 20px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    background: linear-gradient(135deg, #925cff, #5426b8);
    box-shadow: 0 0 35px rgba(146, 92, 255, 0.3);
    font-size: 32px;
}

.welcome h1 {
    font-size: 38px;
    margin-bottom: 12px;
}

.welcome h1 span {
    color: var(--primary);
}

.welcome p {
    color: var(--muted);
    line-height: 1.7;
}

/* MODES */

.mode-selection {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.mode-card {
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--surface);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: 0.25s;
}

.mode-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
}

.mode-card.active {
    border-color: var(--primary);
    background: rgba(146, 92, 255, 0.1);
}

.mode-card span {
    display: block;
    font-size: 25px;
    margin-bottom: 12px;
}

.mode-card strong {
    display: block;
    font-size: 16px;
    margin-bottom: 8px;
}

.mode-card small {
    color: var(--muted);
    line-height: 1.5;
}

/* CHAT CONTAINER */

.chat-container {
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    overflow: hidden;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.25);
}

.chat-header {
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.chat-header h2 {
    font-size: 17px;
    margin-bottom: 7px;
}

.chat-header p {
    color: var(--muted);
    font-size: 12px;
}

.online-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #36d399;
    margin-right: 5px;
}

.clear-button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 9px 13px;
    border-radius: 8px;
    cursor: pointer;
}

.clear-button:hover {
    color: white;
    border-color: var(--primary);
}

/* CHAT MESSAGES */

.chat-messages {
    height: 420px;
    overflow-y: auto;
    padding: 25px;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 25px;
    align-items: flex-start;
}

.message-avatar {
    min-width: 35px;
    height: 35px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: #29203f;
    color: #c5a7ff;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-avatar {
    background: #252d43;
    color: white;
}

.message-content {
    max-width: 80%;
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--surface-light);
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.user-message .message-content {
    background: rgba(146, 92, 255, 0.16);
}

.message-content strong {
    display: block;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--primary-hover);
}

.message-content p {
    color: #e0e3ed;
    font-size: 14px;
    white-space: pre-wrap;
}

/* INPUT AREA */

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--border);
}

.chat-input-area textarea {
    flex: 1;
    resize: none;
    min-height: 48px;
    max-height: 120px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: white;
    outline: none;
    font-family: inherit;
    font-size: 14px;
}

.chat-input-area textarea:focus {
    border-color: var(--primary);
}

.chat-input-area button {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: 0.2s;
}

.chat-input-area button:hover {
    background: var(--primary-hover);
}

.chat-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.disclaimer {
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    padding: 0 10px 18px;
}

/* MOBILE DESIGN */

@media (max-width: 600px) {

    .header {
        padding: 0 5%;
    }

    .app {
        margin: 35px auto;
    }

    .welcome h1 {
        font-size: 30px;
    }

    .mode-selection {
        grid-template-columns: 1fr;
    }

    .chat-messages {
        height: 400px;
        padding: 15px;
    }

    .message-content {
        max-width: 90%;
    }

}

/* =====================================
   ANSWER LENGTH SETTINGS
===================================== */

.answer-settings {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 15px 18px;
    margin-top: 5px;
    margin-bottom: 5px;
    color: #aaa;
    font-size: 13px;
}

.answer-settings > span {
    font-weight: 600;
    color: #d5d0e5;
    margin-right: 5px;
}

.answer-option {
    background: #171522;
    color: #bdb7cc;
    border: 1px solid #332b48;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
}

.answer-option:hover {
    background: #292039;
    color: white;
    border-color: #9257e8;
    transform: translateY(-2px);
}

.answer-option.active {
    background: linear-gradient(135deg, #7138c9, #a044ff);
    color: white;
    border-color: #a66cff;
    box-shadow: 0 0 14px rgba(145, 75, 255, 0.25);
}


/* =====================================
   CHAT INPUT IMPROVEMENTS
===================================== */

.chat-form {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-top: 5px;
    background: #15131f;
    border: 1px solid #332b48;
    border-radius: 15px;
}

.chat-form textarea {
    flex: 1;
    width: 100%;
    resize: none;
    outline: none;
    background: transparent;
    color: white;
    border: none;
    font-family: inherit;
    font-size: 14px;
    padding: 8px;
}

.chat-form textarea::placeholder {
    color: #777184;
}

.chat-form button {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #7138c9, #a044ff);
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: 0.25s ease;
}

.chat-form button:hover {
    transform: scale(1.07);
    box-shadow: 0 0 15px rgba(145, 75, 255, 0.4);
}

.chat-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}


/* =====================================
   MOBILE RESPONSIVENESS
===================================== */

@media (max-width: 500px) {

    .answer-settings {
        gap: 7px;
        padding: 12px 8px;
    }

    .answer-settings > span {
        width: 100%;
        margin-bottom: 3px;
    }

    .answer-option {
        padding: 8px 13px;
    }

}

/* ==========================================
   HANDYAI 6.0 - MARKDOWN STYLING
   ========================================== */

.message-text {
    color: #e6e1f0;
    font-size: 14px;
    line-height: 1.75;
    overflow-wrap: anywhere;
}

.message-text p {
    margin: 0 0 12px;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4 {
    color: #ffffff;
    margin: 20px 0 10px;
    line-height: 1.4;
}

.message-text h1 {
    font-size: 23px;
}

.message-text h2 {
    font-size: 20px;
}

.message-text h3 {
    font-size: 17px;
}

.message-text strong {
    color: #ffffff;
    font-weight: 700;
}

.message-text em {
    color: #d5c5f5;
}

.message-text ul,
.message-text ol {
    padding-left: 24px;
    margin: 10px 0 16px;
}

.message-text li {
    margin-bottom: 7px;
}

.message-text blockquote {
    border-left: 3px solid #9257e8;
    padding: 8px 14px;
    margin: 14px 0;
    background: rgba(145, 75, 255, 0.08);
    border-radius: 0 8px 8px 0;
}

.message-text a {
    color: #b68aff;
    text-decoration: underline;
}

.message-text hr {
    border: none;
    border-top: 1px solid #393147;
    margin: 18px 0;
}

.message-text code {
    background: #211b2d;
    color: #d6adff;
    padding: 3px 6px;
    border-radius: 5px;
    font-family: Consolas, monospace;
    font-size: 13px;
}

/* CODE BLOCK */

.ai-code-block {
    margin: 15px 0;
    border: 1px solid #393047;
    border-radius: 10px;
    overflow: hidden;
    background: #100e17;
    max-width: 100%;
}

.code-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 13px;
    background: #211b2d;
    border-bottom: 1px solid #393047;
    color: #bca8db;
    font-size: 12px;
}

.code-copy-button {
    background: #7138c9;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: 0.2s;
}

.code-copy-button:hover {
    background: #9257e8;
}

.ai-code-block pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    white-space: pre;
    line-height: 1.6;
}

.ai-code-block pre code {
    background: transparent;
    color: #e6e1f0;
    padding: 0;
    border-radius: 0;
    font-size: 13px;
    font-family: Consolas, "Courier New", monospace;
}

/* MOBILE */

@media (max-width: 600px) {

    .message-text {
        font-size: 13px;
    }

    .message-text h1 {
        font-size: 20px;
    }

    .message-text h2 {
        font-size: 18px;
    }

    .ai-code-block pre {
        padding: 12px;
    }

}

/* ==========================================
   HANDYAI - PLANNER CONFIRMATION
========================================== */

.planner-confirmation {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.planner-confirmation button {
    padding: 10px 18px;
    border-radius: 9px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}

.planner-confirm {
    background: var(--primary);
    color: white;
    border-color: var(--primary) !important;
}

.planner-confirm:hover {
    background: var(--primary-hover);
}

.planner-cancel {
    background: var(--surface-light);
    color: var(--text);
}

.planner-cancel:hover {
    border-color: var(--primary);
}

.planner-confirmation button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* ==========================================
   HANDYAI - FINAL PHONE & TABLET LAYOUT
========================================== */

html {
    width: 100%;
    overflow-x: hidden;
    scroll-padding-top: 16px;
}

body {
    width: 100%;
    overflow-x: hidden;
}

button,
textarea {
    touch-action: manipulation;
}

.header {
    min-height: 70px;
    height: auto;
    gap: 12px;
    padding: 12px clamp(16px, 5vw, 8%);
}

.logo {
    flex-shrink: 0;
}

.back-link {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    text-align: right;
}

.app {
    width: min(900px, calc(100% - 32px));
    margin: clamp(28px, 5vw, 55px) auto;
}

.chat-container,
.chat-messages,
.message-content,
.ai-code-block {
    min-width: 0;
    max-width: 100%;
}

.chat-messages {
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.message {
    min-width: 0;
}

.message-content {
    width: fit-content;
    max-width: min(80%, 720px);
    overflow-wrap: anywhere;
}

.message-text,
.message-content p {
    overflow-wrap: anywhere;
    word-break: normal;
}

.chat-form {
    width: 100%;
    min-width: 0;
    align-items: flex-end;
}

.chat-form textarea {
    min-width: 0;
    min-height: 44px;
    max-height: 150px;
    line-height: 1.5;
    font-size: 16px;
}

.chat-form button,
.clear-button,
.answer-option,
.mode-card,
.planner-confirmation button {
    touch-action: manipulation;
}

.chat-form button {
    width: 46px;
    height: 46px;
    min-width: 46px;
}

.ai-code-block pre {
    max-width: 100%;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
    .header {
        padding: 11px 16px;
    }

    .logo {
        font-size: 22px;
    }

    .back-link {
        font-size: 13px;
    }

    .app {
        width: calc(100% - 24px);
        margin: 26px auto;
    }

    .welcome {
        margin-bottom: 24px;
    }

    .ai-icon {
        width: 56px;
        height: 56px;
        margin-bottom: 15px;
        border-radius: 17px;
        font-size: 27px;
    }

    .welcome h1 {
        font-size: clamp(27px, 7vw, 32px);
        line-height: 1.2;
    }

    .welcome p {
        max-width: 460px;
        margin-inline: auto;
        font-size: 14px;
        line-height: 1.6;
    }

    .mode-selection {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-bottom: 17px;
    }

    .mode-card {
        min-width: 0;
        padding: 16px 13px;
    }

    .mode-card strong {
        font-size: 14px;
        line-height: 1.35;
    }

    .mode-card small {
        display: block;
        font-size: 12px;
        line-height: 1.45;
    }

    .chat-container {
        border-radius: 14px;
    }

    .chat-header {
        padding: 15px;
        gap: 10px;
    }

    .chat-header h2 {
        font-size: 16px;
    }

    .chat-header p {
        font-size: 11px;
    }

    .clear-button {
        min-height: 40px;
        padding: 8px 10px;
        white-space: nowrap;
        font-size: 12px;
    }

    .chat-messages {
        height: min(52vh, 430px);
        min-height: 280px;
        padding: 14px 11px;
    }

    .message {
        gap: 8px;
        margin-bottom: 18px;
    }

    .message-avatar {
        min-width: 30px;
        width: 30px;
        height: 30px;
        border-radius: 9px;
        font-size: 13px;
    }

    .message-content {
        max-width: calc(100% - 38px);
        padding: 11px 12px;
        border-radius: 11px;
    }

    .message-content strong {
        font-size: 12px;
    }

    .message-content p,
    .message-text {
        font-size: 13px;
        line-height: 1.65;
    }

    .answer-settings {
        gap: 7px;
        padding: 12px;
    }

    .answer-settings > span {
        width: 100%;
        margin: 0 0 2px;
    }

    .answer-option {
        min-height: 38px;
        padding: 8px 12px;
        font-size: 12px;
    }

    .chat-form {
        gap: 8px;
        padding: 9px;
        border-radius: 12px;
    }

    .chat-form textarea {
        min-height: 44px;
        padding: 10px 7px;
        font-size: 16px;
    }

    .chat-form button {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }

    .disclaimer {
        padding: 0 12px 14px;
        font-size: 10px;
        line-height: 1.5;
    }

    .planner-confirmation {
        gap: 8px;
    }

    .planner-confirmation button {
        min-height: 42px;
        padding: 10px 13px;
    }

    .ai-code-block pre {
        font-size: 12px;
        padding: 10px;
    }
}

@media (max-width: 390px) {
    .header {
        padding-inline: 12px;
    }

    .logo {
        font-size: 20px;
    }

    .back-link {
        font-size: 12px;
    }

    .app {
        width: calc(100% - 20px);
    }

    .mode-selection {
        grid-template-columns: 1fr;
    }

    .mode-card {
        padding: 14px;
    }

    .chat-header {
        align-items: flex-start;
    }

    .clear-button {
        padding-inline: 8px;
        font-size: 11px;
    }

    .answer-settings {
        gap: 6px;
        padding-inline: 9px;
    }

    .answer-option {
        flex: 1;
        padding-inline: 7px;
    }
}

@media (max-width: 330px) {
    .header {
        align-items: flex-start;
        flex-direction: column;
    }

    .back-link {
        min-height: 34px;
    }

    .chat-header {
        flex-direction: column;
    }

    .message-content {
        max-width: calc(100% - 34px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .mode-card,
    .answer-option,
    .chat-form button {
        transition: none !important;
    }
}
