:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-border: #dfe3e8;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;
    --color-primary: #3a6df0;
    --color-primary-dark: #2952c8;
    --color-danger: #d64550;
    --color-success: #1f9d55;
    --radius: 8px;
    --max-width: 720px;
}

* { box-sizing: border-box; }

html {
    /* iOSのSafariは16px未満の入力欄フォーカス時に自動ズームするため、基準を明示的に16pxにする */
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 16px;
}

.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.app-header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.app-header .brand {
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--color-text);
}
.app-header nav {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    flex-wrap: wrap;
}
.app-header .current-user {
    color: var(--color-text-muted);
}
.logout-form {
    display: inline;
    margin: 0;
}
.link-button {
    display: inline;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: var(--color-primary);
    cursor: pointer;
    min-height: auto;
}
.link-button:hover {
    text-decoration: underline;
}

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}
.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
}
.auth-card h1 {
    margin: 0 0 4px;
    font-size: 1.3rem;
    text-align: center;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--color-text-muted);
    margin: 0 0 20px;
    font-size: 0.9rem;
}

form label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.9rem;
}
form input[type="text"],
form input[type="password"],
form textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}
form select {
    padding: 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface);
    min-height: 44px;
}
form button {
    display: inline-block;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 12px 18px;
    font-size: 1rem;
    cursor: pointer;
    /* タップ領域を確保(モバイルでの押しやすさのため約44px以上を目安に) */
    min-height: 44px;
}
form button:hover { background: var(--color-primary-dark); }
form button.danger { background: var(--color-danger); }

.inline-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 8px;
}
.inline-form input[type="text"] { width: auto; flex: 1; min-width: 160px; }

.error {
    background: #fdecea;
    color: var(--color-danger);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
}
.success {
    background: #e8f8ee;
    color: var(--color-success);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
}
.notice {
    background: #fff6e5;
    color: #8a6100;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
}

.channels {
    list-style: none;
    margin: 0;
    padding: 0;
}
.channels li {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}
.channels a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    color: var(--color-text);
}
.channel-name { font-weight: bold; }
.channel-meta { color: var(--color-text-muted); font-size: 0.85rem; }

.messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}
.message {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.message header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 6px;
    gap: 8px;
}
.message-body {
    margin: 0 0 6px;
    white-space: pre-wrap;
    word-break: break-word;
}
.message-image img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 6px;
    display: block;
    margin-bottom: 6px;
}
.download-link {
    font-size: 0.85rem;
}

.post-form textarea {
    resize: vertical;
}
.post-form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.hint {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    margin-top: 8px;
}

.table-scroll {
    overflow-x: auto;
}
.user-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.user-table th, .user-table td {
    padding: 10px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    font-size: 0.9rem;
    white-space: nowrap;
}
.user-table .actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.user-table .actions form { margin: 0; }
.badge {
    display: inline-block;
    background: #eef1f5;
    color: var(--color-text-muted);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.75rem;
    margin-right: 4px;
}
.badge-warn {
    background: #fdecea;
    color: var(--color-danger);
}
.badge-ok {
    background: #e8f8ee;
    color: var(--color-success);
}

.admin-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 16px;
}
.admin-tabs a {
    padding: 8px 14px;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.admin-tabs a.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: bold;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.search-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}
.search-form input[type="text"] {
    flex: 1;
    min-width: 160px;
    width: auto;
    margin-top: 0;
}
.search-summary {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
}
.search-results {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.search-results .message header {
    justify-content: flex-start;
    gap: 10px;
}
.search-attachment {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin: 0 0 6px;
}
.jump-link {
    font-size: 0.85rem;
}
mark {
    background: #fff2a8;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

.message:target {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.checkbox {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    width: auto !important;
}

@media (max-width: 480px) {
    .container { padding: 12px; }
    .app-header-inner { flex-direction: column; align-items: flex-start; }

    /* 狭い画面では横並びフォームを縦積みにし、要素を全幅にしてタップしやすくする */
    .inline-form,
    .search-form {
        flex-direction: column;
        align-items: stretch;
    }
    .inline-form input[type="text"],
    .search-form input[type="text"],
    .inline-form select,
    .search-form select,
    .inline-form button,
    .search-form button {
        width: 100%;
    }

    .post-form-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .post-form-actions button {
        width: 100%;
    }

    .user-table .actions {
        flex-direction: column;
        align-items: stretch;
    }
    .user-table .actions button {
        width: 100%;
    }
}
