:root {
    --bg: #f6f8fb;
    --panel: #ffffff;
    --line: #d9e1ec;
    --text: #203040;
    --accent: #0078d4;
    --danger: #c42847;
    --success: #107c10;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    background: linear-gradient(180deg, #f4f8fc 0%, #eef3fa 100%);
    color: var(--text);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1.2rem;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.topbar .brand {
    font-weight: 700;
}

.topbar nav {
    display: flex;
    gap: 0.9rem;
    flex-wrap: wrap;
}

.topbar a {
    text-decoration: none;
    color: var(--accent);
    font-weight: 600;
}

.container {
    max-width: 960px;
    margin: 1.2rem auto;
    padding: 0 1rem;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1rem;
}

.narrow {
    max-width: 460px;
    margin: 0 auto;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.form-grid {
    display: grid;
    gap: 0.7rem;
    margin-top: 1rem;
}

input,
textarea,
button {
    font: inherit;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
}

button,
.button-link {
    display: inline-block;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #ffffff;
    padding: 0.55rem 0.9rem;
    text-decoration: none;
    cursor: pointer;
}

.button-link.secondary {
    background: #5b7086;
}

button.danger {
    background: var(--danger);
}

.button-row {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.8rem;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 0.55rem;
    text-align: left;
    vertical-align: top;
}

.actions {
    display: flex;
    gap: 0.55rem;
    align-items: center;
    flex-wrap: wrap;
}

.history-row {
    border-left: 4px solid transparent;
}

.history-reset {
    background: #f5fbff;
    border-left-color: #2f7fb8;
}

.history-files {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.history-audio {
    width: min(420px, 100%);
    min-width: 300px;
}

.history-thumb {
    width: 86px;
    height: 64px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.history-prompt-details {
    margin-top: 0.35rem;
}

.history-prompt {
    margin: 0.4rem 0 0;
    padding: 0.6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdff;
    max-width: 520px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.9rem;
}

.modal-open {
    overflow: hidden;
}

.image-modal {
    position: fixed;
    inset: 0;
    background: rgba(18, 24, 30, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
}

.image-modal[hidden] {
    display: none !important;
}

.image-modal-content {
    position: relative;
    max-width: min(92vw, 980px);
    max-height: 92vh;
}

.image-modal-content img {
    display: block;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 10px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.4);
}

.image-modal-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: #ffffff;
    color: #172432;
    border: 1px solid #c7d3e2;
    font-weight: 700;
    line-height: 1;
    padding: 0;
}

.history-files a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.flash-list {
    list-style: none;
    padding: 0;
}

.flash {
    border-radius: 8px;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.55rem;
}

.flash-error {
    background: #ffe8ea;
    border: 1px solid #f0b4be;
}

.flash-success {
    background: #e6f6e6;
    border: 1px solid #bde5bd;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

@media (max-width: 640px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    th,
    td {
        font-size: 0.92rem;
    }
}
