@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@600&family=Roboto:wght@400;500;600&display=swap');

:root {
    --primary-color: #000000;
    --background-color: #f5f5f5;
    --container-bg: #ffffff;
    --font-main: 'Roboto', sans-serif;
    --font-heading: 'Montserrat', sans-serif;
    --border-radius: 12px;
    --shadow-default: 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.12);
    /* Unified panel height baseline (match /how preset), and caret sizing */
    --app-panel-height: 340px;
    --caret-btn-size: 28px;
    --caret-icon-size: 14px;
    --upload-list-height: 80px;
}

@media (max-width: 600px) {
    :root {
        --app-panel-height: 55vh;
        --caret-btn-size: 36px;
        --caret-icon-size: 18px;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    padding: 16px;
    background-color: var(--background-color);
    color: #333;
}

.container {
    width: 100%;
    max-width: 390px;
    margin: 20px auto;
    background-color: var(--container-bg);
    padding: 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-default);
}

.header {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    margin: 20px auto;
}

.content {
    width: 90%;
    margin: 40px auto 20px;
}

.content p {
            font-size: 16px;
            margin: auto 10px 10px 10px;
            line-height: 1.0;
            text-align: justify;
            -webkit-hyphens: none;
            -ms-hyphens: none;
            hyphens: none;
        }

/* DEB answer area: match styling used on /how for readable paragraphs */
#deb-answer,
#deb-answer pre,
#deb-answer div {
    font-family: var(--font-main);
    font-size: 16px;
    line-height: 1.0;        /* same compact line-height as /how */
    text-align: justify;     /* justify text for even spacing */
    color: #222;
    padding: 8px 0;          /* keep vertical padding only */
    font-weight: 400;       /* normal weight for DEB responses */
    word-break: break-word;
    white-space: pre-wrap;
    min-height: 12em;        /* reserve space for streamed response */
    -webkit-hyphens: none;
    -ms-hyphens: none;
    hyphens: none;           /* prevent automatic hyphenation in tall blocks */
}

#deb-answer .error-message {
    color: #900;
    font-weight: 600;
}

.content p.left-heading {
    text-align: left;
}

.content p.justify {
    text-align: justify;
    padding: 10px;
    font-size: 0.85rem;
    color: #666;
}

.content p.centered-heading {
    text-align: center;
}

.ai-input-container {
    height: 60px;
    width: 90%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    background-color: #222;             /* for visual clarity */
    padding: 8px 10px;                  /* adjust spacing */
    border-radius: 8px;                 /* for rounded corners */
    justify-content: flex-start;        /* rely on gap for spacing between input and button */
    gap: 16px;                          /* clearer separation between input and send */
    overflow: hidden;                   /* guard against Android overflow */
}

.ai-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 15px;
    padding: 12px;
    outline: none;
    max-height: 6em;
    line-height: 1.4;
}

.ai-input::placeholder {
  font-size: 15px; /* smaller placeholder */
}

.ai-send {
    width: 28px;
    height: 28px;
    cursor: pointer;
    filter: invert(85%); /* make light on dark bg; adjust as needed */
    transition: opacity 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
    object-fit: contain;
    -webkit-tap-highlight-color: transparent;
    margin-left: auto;                 /* push send button to the far right */
    margin-right: 14px;                /* ensure more space after the send button */
}

.ai-upload {
    height: 28px;
    width: 28px;
}

.ai-send:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.circle-button {
    background-color: #e0e0e0;       /* Light grey */
    border: none;
    border-radius: 50%;              /* Makes it circular */
    padding: 15px;                   /* Controls size around image */
    cursor: pointer;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* File uploader styles */
.file-uploader {
    width: 100%;
    background: #ffffff;
    border-radius: 5px;
    box-shadow: var(--shadow-default);
}

.uploader-header {
    display: flex;
    padding: 20px;
    background: #000000;
    align-items: center;
    border-radius: 5px 5px 0 0;
    justify-content: space-between; /* default for shared uploader headers */
    color: #ffffff;
}

/* Scope plimit header alignment to that page only */
.page-plimit .uploader-header {
    justify-content: flex-start;
}

.file-completed-status {
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-main);
}

.file-list {
    list-style: none;
    width: 100%;
    padding-bottom: 10px;
    max-height: 400px;
    overflow-y: auto;
    scrollbar-color: #000000 transparent;
    scrollbar-width: thin;
    position: relative;
}

.file-list:has(li) {
    padding: 20px;
}

.file-list.caret-target {
    overflow-y: auto;
}

.file-list.has-carets {
    padding-right: calc(20px + var(--caret-btn-size) + 8px);
}

.file-list .caret {
    position: absolute;
    right: 4px;
    width: var(--caret-btn-size);
    height: var(--caret-btn-size);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    z-index: 2;
}

.file-list .caret.up { top: 6px; }
.file-list .caret.down { bottom: 6px; }

.file-list .caret img {
    width: var(--caret-icon-size);
    height: var(--caret-icon-size);
    display: block;
    pointer-events: none;
}

.file-list .caret:active {
    transform: scale(0.96);
}

.file-item {
    display: flex;
    gap: 14px;
    margin-bottom: 22px;
}

.file-item:last-child {
    margin-bottom: 0;
}

.file-content-wrapper {
    flex: 1;
}

.file-content {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
}

.file-name {
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-main);
}

.file-info {
    display: flex;
    gap: 5px;
}

.file-info small {
    color: #5c5c5c;
    margin-top: 5px;
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-main);
}

.file-status {
    color: #000000;
}

.file-progress-bar {
    width: 100%;
    height: 3px;
    margin-top: 10px;
    border-radius: 30px;
    background: #d9d9d9;
}

.file-progress {
    width: 0;
    height: inherit;
    border-radius: inherit;
    background: #000000;
}

.file-upload-box {
    margin: 10px 20px;
    border-radius: 5px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #000000;
    transition: all 0.2s ease;
}

.file-upload-box.active {
    border: 2px solid #5145BA;
    background: #F3F6FF;
}

.cancel-button {
    align-self: center;
    border: none;
    outline: none;
    background: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #000000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
}

.cancel-button i {
    line-height: 1;
    font-size: 20px;
}

.cancel-button:hover {
    color: #000;
    opacity: 0.7;
}

.box-title {
    font-size: 1.05rem;
    font-weight: 500;
    color: #626161;
    font-family: var(--font-main);
}

.file-upload-box.active .box-title {
    pointer-events: none;
}

.file-browse-button {
    color: #000000;
    cursor: pointer;
}

.file-browse-button:hover {
    text-decoration: underline;
}

.text-input {
    width: 90%;
    margin: 0 20px 20px;
    padding: 12px;
    font-size: 15px; /* match .ai-input size */
    line-height: 1.4; /* match .ai-input line height */
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    background-color: #fff;
    color: #333;
    box-sizing: border-box;
}

.buttons {
    width: 90%;
    margin: auto auto 30px auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.buttons-upload {
    width: 90%;
    margin: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Ensure buttons stretch to container width for consistent sizing */
.buttons .button,
.buttons-upload .button {
    width: 100%;
}

.button {
    font-family: var(--font-heading);
    padding: 16px 16px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    cursor: pointer;
    text-align: center;
    background-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-default);
    transition: all 0.2s ease-in-out;
    text-decoration: none;
}

.button:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.button:active {
    transform: scale(0.98);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.button:focus-visible {
    outline: 2px solid var(--primary-color);
}

.black-container {
    display: block;              /* block layout avoids flex item spacing issues */
    padding: 20px;
    background: #000000;
    border-radius: 5px 5px 0 0;
    color: #ffffff;
}

.white-container {
    display: flex;
    padding: 20px 20px 10px 20px;
    background: #ffffff;
    align-items: center;
    border-radius: 5px 5px 0 0;
    justify-content: space-between;
    color: #000000;
    /* Fix height across pages to match /how baseline; scrolling is enabled on non-baseline pages via body class */
    min-height: var(--app-panel-height);
    max-height: 844px;
    box-sizing: border-box;
}

/* Baseline /how page: no inner scroll and no extra padding for carets */
.page-how .white-container {
    overflow: visible;
    padding-right: 20px; /* original padding */
}

.page-help .white-container {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 20px 5px;
}

.page-help .white-container p {
    margin: 0;
    line-height: 1.0;
}

.page-help .white-container p:last-child {
    margin-bottom: 0;
}

.page-help .warning-text {
    color: #880808;
    font-weight: 600;
}

.page-help .white-container .buttons-upload {
    width: auto;
    margin: 0;
    align-self: center;
}

.page-help .white-container .buttons-upload .circle-button {
    margin: 0;
}

/* Upload page remains fluid and unmodified */
.page-upload .white-container {
    min-height: auto;
    max-height: none;
    overflow: visible;
    padding-right: 20px;
}

/* Other pages can scroll if content exceeds baseline height */
body:not(.page-upload):not(.page-how) .white-container {
    overflow-y: auto;
}

/* Right padding only when carets are present */
.white-container.has-carets {
    padding-right: calc(20px + var(--caret-btn-size) + 8px);
}

/* Caret buttons (injected by JS only when overflow is detected) */
.white-container .caret {
    position: absolute;
    right: 6px;
    width: var(--caret-btn-size);
    height: var(--caret-btn-size);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    z-index: 2;
}
.white-container .caret.up { top: 6px; }
.white-container .caret.down { bottom: 6px; }
.white-container .caret img {
    width: var(--caret-icon-size);
    height: var(--caret-icon-size);
    display: block;
    pointer-events: none;
}
.white-container .caret:active { transform: scale(0.96); }

/* Keep content clear of carets when present */
.white-container.has-carets p,
.white-container.has-carets div,
.white-container.has-carets pre {
    margin-right: 6px;

}

/* Chat-only: stack DEB header, answer, and notice vertically */
.white-container.stacked {
    display: block;        /* override flex for stacking */
    max-height: var(--app-panel-height); /* keep chat panel within app bounds */
    overflow-y: auto;      /* allow internal scroll when content exceeds height */
    position: relative;    /* ensure caret buttons anchor correctly */
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spin-loading {
  animation: spin 1s linear infinite;
  transform-origin: center;
}


/* Mobile/Android: align chat button size closer to home buttons, avoid zoom */
@media (pointer: coarse), (max-width: 640px) {
  .ai-input-container {
    padding: 8px 12px;
  }
  .ai-input {
    font-size: 16px; /* prevent Android zoom */
    line-height: 1.4;
    padding: 12px 10px;
  }
  .ai-send,
  .ai-upload {
    width: 44px;  /* closer to .button visual height */
    height: 44px; /* still a bit smaller than the text field */
    flex-shrink: 0;
  }
  .ai-spinner {
    width: 44px;
    height: 44px;
  }
}

/* Responsive adjustments: prevent overflow and hide send button on mobile/Telegram */
.ai-input-container {
    flex-wrap: nowrap;           /* keep input and icon on one line */
    box-sizing: border-box;      /* include padding in width calc */
}


/* Hide send button on mobile and Telegram miniapp */
@media (max-width: 640px), (pointer: coarse) {
  .ai-send { display: none; }
}
.tg-webapp .ai-send { display: none !important; }


/* Fallback for browsers without flex gap support */
@supports not (gap: 1rem) {
  .ai-input-container .ai-send { margin-left: auto; }
}

/* Added centralized spinner handling for mobile/Telegram processing */

.ai-spinner {
  display: none;
  width: 28px;
  height: 28px;
  filter: invert(85%);
  object-fit: contain;
}

.ai-input-container.processing {
  justify-content: center;
}

.ai-input-container.processing .ai-input,
.ai-input-container.processing .ai-send {
  display: none !important;
}

/* Ensure the label wrapper doesn’t affect centering */
.ai-input-container.processing label {
  display: none !important;
}

.ai-input-container.processing .ai-spinner {
  display: block;
}

.header a.home-link,
.header a.home-link:visited,
.header a.home-link:hover,
.header a.home-link:active {
    color: inherit;
    text-decoration: none;
}

/* Visually hidden but accessible text helper */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Ensure verify page white container matches chat page height when empty */
.page-verify .white-container {
    min-height: 12em; /* align with #deb-answer min-height on chat */
}

/* Right-align the internship anchor rendered inside #deb-answer when the sentinel is present */
.internship-link {
    text-align: right;
    margin-top: 8px;
}