/* ===================================================================
   Herald Control — Stylesheet
   WCAG 2.1 AA · High contrast · No animations · Vanilla CSS
   =================================================================== */

/* --- Reset & base -------------------------------------------------- */

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

html, body {
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: #1a1a1a;
    background: #f5f5f5;
}

/* --- Skip link (JAWS) ---------------------------------------------- */

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 1000;
    padding: 0.75rem 1.25rem;
    background: #005fcc;
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.skip-link:focus {
    position: fixed;
    left: 0;
    top: 0;
}

/* --- Focus ring (global) ------------------------------------------- */

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid #005fcc;
    outline-offset: 2px;
}

/* --- Header -------------------------------------------------------- */

header[role="banner"] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 1.25rem;
    background: #1a1a2e;
    color: #f0f0f0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-name {
    font-size: 1.125rem;
    font-weight: 700;
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.875rem;
}

.header-right a {
    color: #c5cadf;
    text-decoration: underline;
}

.header-right a:hover {
    color: #fff;
}

.user-email {
    color: #c5cadf;
}

/* --- Status indicator ---------------------------------------------- */

.status-indicator {
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-indicator::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.375rem;
    vertical-align: middle;
}

.status-online::before {
    background: #4caf50;
}

.status-offline::before {
    background: #ef5350;
}

/* --- App body (sidebar + main) ------------------------------------- */

.app-body {
    display: flex;
    margin-top: 56px;
    height: calc(100vh - 56px);
}

/* --- Sidebar ------------------------------------------------------- */

.sidebar {
    width: 250px;
    min-width: 250px;
    background: #fff;
    border-right: 1px solid #d0d0d0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar h2 {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #555;
    padding: 1rem 1rem 0.5rem;
}

#channel-list {
    list-style: none;
    flex: 1;
}

#channel-list li a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    color: #1a1a1a;
    text-decoration: none;
    border-left: 3px solid transparent;
}

#channel-list li a:hover {
    background: #e8eaf6;
}

#channel-list li a.active,
#channel-list li a[aria-current="page"] {
    background: #e3f2fd;
    border-left-color: #005fcc;
    font-weight: 600;
}

.channel-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 0.375rem;
    border-radius: 11px;
    background: #c62828;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.no-channels {
    padding: 1rem;
    color: #666;
    font-style: italic;
}

/* --- Main content -------------------------------------------------- */

main[role="main"] {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Channel list prompt ------------------------------------------- */

.channel-list-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #555;
    text-align: center;
    padding: 2rem;
}

.channel-list-prompt h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: #1a1a1a;
}

/* --- Channel view (messages + form) -------------------------------- */

.channel-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.channel-heading {
    font-size: 1.125rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid #d0d0d0;
    background: #fff;
    flex-shrink: 0;
}

/* --- Message list -------------------------------------------------- */

#message-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.message {
    padding: 0.625rem 0.75rem;
    border-radius: 6px;
    background: #fff;
    border: 1px solid #e0e0e0;
    max-width: 85%;
}

.message.own-message {
    background: #e3f2fd;
    border-color: #bbdefb;
    align-self: flex-end;
}

.message-header {
    display: flex;
    align-items: baseline;
    gap: 0.625rem;
    margin-bottom: 0.25rem;
}

.sender {
    font-weight: 700;
    font-size: 0.875rem;
    color: #1a1a1a;
}

.message-header time {
    font-size: 0.75rem;
    color: #545454;
}

.message-content {
    font-size: 0.9375rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-reply {
    margin-top: 0.5rem;
    padding: 0.5rem 0.625rem;
    background: #f0f4f8;
    border-left: 3px solid #90a4ae;
    border-radius: 0 4px 4px 0;
    font-size: 0.875rem;
}

.message-reply .reply-sender {
    font-size: 0.8125rem;
    color: #37474f;
}

.message-reply p {
    margin-top: 0.125rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.no-messages {
    color: #666;
    font-style: italic;
    text-align: center;
    padding: 2rem 0;
}

/* --- Post form ----------------------------------------------------- */

#post-form {
    flex-shrink: 0;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid #d0d0d0;
    background: #fff;
}

#post-form label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: #333;
}

.input-row {
    display: flex;
    gap: 0.5rem;
}

#message-input {
    flex: 1;
    resize: vertical;
    padding: 0.5rem 0.625rem;
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.4;
    border: 1px solid #bdbdbd;
    border-radius: 4px;
    background: #fff;
    color: #1a1a1a;
}

#message-input:focus {
    border-color: #005fcc;
}

#send-btn {
    align-self: flex-end;
    padding: 0.5rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: #fff;
    background: #1565c0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

#send-btn:hover {
    background: #0d47a1;
}

#send-btn:disabled {
    background: #90a4ae;
    cursor: not-allowed;
}

.post-error {
    padding: 0.5rem 1.25rem;
    background: #fce4ec;
    color: #b71c1c;
    font-size: 0.875rem;
    font-weight: 600;
}

/* --- Login page ---------------------------------------------------- */

.login-container {
    max-width: 400px;
    margin: 6rem auto 0;
    padding: 2rem;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
}

.login-container h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.login-container h2 {
    font-size: 1.125rem;
    font-weight: 400;
    color: #555;
    margin-bottom: 1.5rem;
}

/* --- Settings page ------------------------------------------------- */

.settings-container {
    max-width: 500px;
    padding: 2rem 1.5rem;
}

.settings-container h1 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.settings-container section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #e0e0e0;
}

.settings-container section:last-child {
    border-bottom: none;
}

.settings-container h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
}

/* --- Shared form styles -------------------------------------------- */

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #333;
}

.field input[type="email"],
.field input[type="password"],
.field input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.625rem;
    font-family: inherit;
    font-size: 1rem;
    border: 1px solid #bdbdbd;
    border-radius: 4px;
    background: #fff;
    color: #1a1a1a;
}

.field input:focus {
    border-color: #005fcc;
}

button[type="submit"] {
    padding: 0.625rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: #1565c0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button[type="submit"]:hover {
    background: #0d47a1;
}

.form-errors {
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: #fce4ec;
    color: #b71c1c;
    border: 1px solid #ef9a9a;
    border-radius: 4px;
    font-weight: 600;
}

.form-success {
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
    border-radius: 4px;
    font-weight: 600;
}

.field-error {
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    color: #b71c1c;
    font-weight: 600;
}

.field-help {
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    color: #555;
}

/* --- Admin portal -------------------------------------------------- */

.admin-portal {
    padding: 1.5rem 2rem;
    overflow-y: auto;
    max-width: 1000px;
}

.admin-nav {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #d0d0d0;
    padding-bottom: 0;
}

.admin-nav a {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: #333;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.admin-nav a:hover {
    background: #e8eaf6;
}

.admin-nav a[aria-current="page"] {
    border-bottom-color: #005fcc;
    color: #005fcc;
}

.admin-messages {
    margin-bottom: 1rem;
}

.admin-portal h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

.admin-form {
    max-width: 500px;
}

.admin-form a {
    margin-left: 1rem;
    color: #333;
}

/* --- Tables -------------------------------------------------------- */

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    background: #fff;
    border: 1px solid #d0d0d0;
}

table caption {
    text-align: left;
    font-size: 0.8125rem;
    color: #555;
    margin-bottom: 0.5rem;
}

th, td {
    text-align: left;
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.875rem;
}

thead th {
    background: #f5f5f5;
    font-weight: 700;
    white-space: nowrap;
}

tbody th {
    font-weight: 600;
}

.actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.actions form {
    display: inline;
}

.actions button,
.actions a {
    font-size: 0.8125rem;
    padding: 0.25rem 0.625rem;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}

.actions button {
    background: #e0e0e0;
    border: 1px solid #bdbdbd;
    color: #1a1a1a;
}

.actions button:hover {
    background: #d0d0d0;
}

.actions a {
    color: #1565c0;
}

/* --- Buttons ------------------------------------------------------- */

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: #1565c0;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.875rem;
}

.btn:hover {
    background: #0d47a1;
}

.btn-danger {
    background: #c62828;
    color: #fff;
    border: 1px solid #b71c1c;
}

.btn-danger:hover {
    background: #b71c1c;
}

/* --- API key display ----------------------------------------------- */

.key-warning {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background: #fff3e0;
    color: #e65100;
    border: 2px solid #ff9800;
    border-radius: 4px;
    font-size: 1rem;
}

.key-display {
    margin-bottom: 1.5rem;
}

.key-display label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.375rem;
}

.key-row {
    display: flex;
    gap: 0.5rem;
}

.key-input {
    flex: 1;
    font-family: monospace;
    font-size: 0.9375rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid #bdbdbd;
    border-radius: 4px;
    background: #fafafa;
}

#copy-btn {
    padding: 0.5rem 1rem;
    font-weight: 600;
    background: #1565c0;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#copy-btn:hover {
    background: #0d47a1;
}

#copy-status {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    color: #2e7d32;
    font-weight: 600;
}

.key-meta {
    max-width: 400px;
    margin-bottom: 1.5rem;
}

.inline-form {
    display: inline;
}

/* --- Footer ------------------------------------------------------- */

.app-footer {
    padding: 0.5rem 1rem;
    text-align: center;
    border-top: 1px solid #d0d0d0;
    background: #fafafa;
}

.version-text {
    font-size: 0.75rem;
    color: #757575;
}
