/* Nostrito Shared Styles */

/* =========================
   CSS Reset & Base Styles
   ========================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Base Typography & Colors */
body {
    font-family: "courier new", monospace;
    color: #999;
    background-color: #111;
    margin: 0;
    padding: 8px;
    line-height: 1.4;
    min-height: 100vh;
}

/* Typography */
h1 {
    color: #0085be;
    margin-bottom: 5px;
    font-size: 1.5em;
}

h2 {
    color: #0085be;
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.2em;
}

a {
    color: #0085be;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* =========================
   Layout Containers
   ========================= */
.page-container {
    width: 90%;
    max-width: 1200px;
    margin: 0 auto;
}

.page-container.narrow {
    max-width: 900px;
}

.page-container.simple {
    width: 100%;
    max-width: 35em;
    padding: 0 15px;
}

.subtitle {
    color: #666;
    margin-bottom: 8px;
    font-style: italic;
}

/* =========================
   Controls & Forms
   ========================= */
.controls {
    margin-bottom: 8px;
    padding: 8px;
    border: 1px solid #333;
    background-color: #1a1a1a;
    border-radius: 3px;
}

.controls label {
    display: block;
    margin-bottom: 5px;
    color: #ccc;
    font-weight: bold;
}

/* Form Elements */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
    padding: 4px;
    background-color: #222;
    border: 1px solid #444;
    color: #fff;
    font-family: monospace;
    font-size: 0.9em;
    border-radius: 2px;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="datetime-local"]:focus,
select:focus,
textarea:focus {
    border-color: #0085be;
    outline: none;
}

/* Specific input sizes */
.controls input[type="text"] {
    width: 100%;
    max-width: 300px;
    margin-right: 10px;
}

.nsec-input {
    width: 100%;
}

/* =========================
   Buttons
   ========================= */
button {
    padding: 4px 8px;
    margin: 2px 3px 2px 0;
    background-color: #0085be;
    color: white;
    border: none;
    cursor: pointer;
    font-family: monospace;
    border-radius: 2px;
    min-height: 36px; /* Better touch targets */
}

button:hover:not(:disabled) {
    background-color: #0099dd;
    opacity: 0.9;
}

button:disabled {
    background-color: #444;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Button Variants */
.button-secondary {
    background-color: #555;
}

.button-secondary:hover:not(:disabled) {
    background-color: #666;
}

.button-danger {
    background-color: #a05;
}

.button-danger:hover:not(:disabled) {
    background-color: #c07;
}

.button-small {
    padding: 4px 8px;
    font-size: 0.8em;
    min-height: 32px;
}

.submit-button {
    padding: 12px 30px;
    font-weight: bold;
    font-size: 1.1em;
    border-radius: 3px;
    margin: 0 10px;
}

/* =========================
   Status & Messages
   ========================= */
.status {
    margin: 4px 0;
    padding: 6px;
    background-color: #222;
    border-left: 3px solid #666;
    font-size: 0.9em;
    border-radius: 2px;
}

.status.connected {
    border-left-color: #0a5;
}

.status.disconnected {
    border-left-color: #a50;
}

.status.error {
    border-left-color: #a05;
}

.message {
    padding: 6px;
    margin: 4px 0;
    border-radius: 3px;
    font-weight: bold;
}

.message.success {
    background-color: #1a3a1a;
    border: 1px solid #0a5;
    color: #5a5;
}

.message.error {
    background-color: #3a1a1a;
    border: 1px solid #a05;
    color: #a55;
}

.empty-state {
    text-align: center;
    color: #666;
    padding: 20px;
    font-style: italic;
}

/* =========================
   Authentication Section
   ========================= */
.nsec-section {
    margin-top: 15px;
    padding: 10px;
    border: 1px solid #555;
    background-color: #222;
    border-radius: 3px;
}

.nsec-section.hidden {
    display: none;
}

.nsec-warning {
    color: #fa5;
    font-size: 0.9em;
    margin-bottom: 10px;
}

/* =========================
   Content Sections
   ========================= */
.content-section {
    border: 1px solid #333;
    background-color: #1a1a1a;
    border-radius: 3px;
    padding: 8px;
    margin-bottom: 8px;
}

.filter-section {
    margin-top: 8px;
    border: 1px solid #333;
    background-color: #1a1a1a;
}

.filter-header {
    padding: 6px;
    cursor: pointer;
    background-color: #222;
    border-bottom: 1px solid #333;
    user-select: none;
}

.filter-header:hover {
    background-color: #333;
}

.filter-content {
    padding: 8px;
    display: none;
}

.filter-content.expanded {
    display: block;
}

/* =========================
   Form Components
   ========================= */
.form-section {
    border: 1px solid #333;
    background-color: #1a1a1a;
    border-radius: 3px;
    padding: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #ccc;
    font-weight: bold;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
}

.form-group textarea {
    min-height: 120px;
    resize: vertical;
}

.form-group .help-text {
    font-size: 0.8em;
    color: #888;
    margin-top: 3px;
}

.filter-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.filter-row label {
    min-width: 80px;
    color: #ccc;
    font-size: 0.9em;
}

.filter-row input,
.filter-row select {
    flex: 1;
}

.filter-buttons {
    margin-top: 15px;
    gap: 10px;
    display: flex;
    flex-wrap: wrap;
}

.filter-status {
    margin-top: 10px;
    padding: 8px;
    background-color: #222;
    border-left: 3px solid #0085be;
    font-size: 0.9em;
    color: #aaa;
}

/* =========================
   Interactive Elements
   ========================= */
.metadata-toggle {
    color: #0085be;
    cursor: pointer;
    font-size: 0.8em;
    margin-left: 10px;
    user-select: none;
}

.metadata-toggle:hover {
    opacity: 0.7;
}

.collapsible {
    cursor: pointer;
    transition: background-color 0.2s;
}

.collapsible:hover {
    background-color: #222;
}

.collapsible::after {
    content: " 📄 Click to collapse";
    color: #0085be;
    font-style: italic;
    font-size: 0.9em;
}

.collapsed::after {
    content: " 📖 Click to expand";
    color: #0085be;
    font-style: italic;
    font-size: 0.9em;
}

/* =========================
   Tags & Metadata
   ========================= */
.tags-builder {
    border: 1px solid #444;
    background-color: #222;
    padding: 10px;
    border-radius: 3px;
}

.tag-input-row {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
    align-items: center;
}

.tag-input-row input {
    margin: 0;
    padding: 4px;
    font-size: 0.8em;
}

.tag-input-row button {
    padding: 4px 8px;
    font-size: 0.8em;
}

.existing-tags {
    margin-bottom: 10px;
}

.tag-item,
.event-tag {
    display: inline-block;
    background-color: #333;
    color: #aaa;
    padding: 2px 6px;
    margin: 2px;
    border-radius: 3px;
    font-size: 0.8em;
    font-family: monospace;
}

.tag-name,
.event-tag-name {
    color: #0085be;
    font-weight: bold;
}

/* =========================
   Chat & Events
   ========================= */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid #333;
    background-color: #1a1a1a;
    min-height: 400px;
}

.messages {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
    border-bottom: 1px solid #333;
}

.message,
.event {
    margin-bottom: 8px;
    padding: 6px;
    background-color: #222;
    border-radius: 3px;
    word-wrap: break-word;
}

.event {
    border: 1px solid #333;
    background-color: #1a1a1a;
}

.message-header,
.event-header {
    font-size: 0.8em;
    color: #888;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
}

.message-author,
.event-author {
    color: #5a5;
    font-weight: bold;
    font-family: monospace;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-author:hover,
.event-author:hover {
    opacity: 0.7;
}

.message-author.own {
    color: #0085be;
}

.event-author.expanded {
    word-break: break-all;
}

.message-time,
.event-time {
    color: #666;
    font-size: 0.8em;
}

.event-kind {
    color: #0085be;
    font-weight: bold;
}

.message-content,
.event-content {
    color: #ccc;
    white-space: pre-wrap;
    line-height: 1.4;
}

.event-content {
    cursor: pointer;
    transition: background-color 0.2s;
}

.event-content:hover {
    background-color: #222;
}

.message-content.deleted {
    color: #666;
    font-style: italic;
}

/* Event metadata */
.event-metadata {
    margin-top: 4px;
    padding: 6px;
    background-color: #222;
    border-left: 3px solid #333;
    display: none;
    font-size: 0.9em;
}

.event-metadata.expanded {
    display: block;
}

.event-metadata-row {
    margin-bottom: 6px;
    display: flex;
    flex-wrap: wrap;
}

.event-metadata-label {
    color: #888;
    min-width: 80px;
    font-weight: bold;
}

.event-metadata-value {
    color: #ccc;
    flex: 1;
    word-break: break-all;
    font-family: monospace;
}

.event-json {
    margin-top: 8px;
    padding: 8px;
    background-color: #111;
    border: 1px solid #444;
    font-family: monospace;
    font-size: 0.8em;
    white-space: pre-wrap;
    color: #999;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.event-json.expanded {
    display: block;
}

/* Message Actions */
.message-actions {
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-actions button {
    background: #333;
    border: none;
    color: #ccc;
    padding: 4px 8px;
    margin-right: 5px;
    font-size: 0.8em;
    cursor: pointer;
    border-radius: 3px;
    min-height: 32px;
}

.message-actions button:hover {
    background: #0085be;
}

/* =========================
   Input & File Handling
   ========================= */
.message-input-container {
    padding: 8px;
    background-color: #222;
    border-top: 1px solid #333;
    position: relative;
}

.input-controls {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
}

.message-input {
    width: 100%;
    min-height: 50px;
    padding: 6px;
    background-color: #111;
    border: 1px solid #444;
    color: #fff;
    font-family: monospace;
    font-size: 0.9em;
    resize: vertical;
}

.message-input:focus {
    border-color: #0085be;
    outline: none;
}

.message-input.dragover {
    border: 2px dashed #0085be;
    background-color: #1a2a3a;
}

/* Reply indicator */
.reply-indicator {
    display: none;
    background: #333;
    padding: 4px 8px;
    margin-bottom: 4px;
    border-left: 3px solid #0085be;
    font-size: 0.9em;
    color: #ccc;
    align-items: center;
}

.reply-indicator.show {
    display: flex;
}

/* Reply prefix in messages */
.reply-prefix {
    display: inline-flex;
    align-items: center;
    font-size: 0.7em;
    color: #0085be;
    margin-right: 8px;
    padding: 2px 6px;
    background-color: rgba(0, 133, 190, 0.15);
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s;
    vertical-align: baseline;
    gap: 4px;
}

.reply-prefix:hover {
    background-color: rgba(0, 133, 190, 0.25);
}

.reply-prefix .reply-identicon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.reply-arrow {
    color: #0085be;
    font-weight: bold;
    margin-right: 4px;
}

.reply-author {
    color: #0085be;
    margin-left: 4px;
}

/* Message highlighting */
.message.highlighted {
    background-color: rgba(0, 133, 190, 0.3) !important;
    transition: background-color 0.3s ease;
}

.cancel-reply {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1.2em;
    float: right;
    margin-top: -2px;
}

.cancel-reply:hover {
    color: #fff;
}

/* File handling */
.file-preview {
    margin: 10px 0;
    padding: 10px;
    background: #333;
    border-radius: 5px;
    border-left: 3px solid #0085be;
}

.file-preview img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 3px;
}

.file-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

/* =========================
   Grid Layouts
   ========================= */
.event-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.submit-section {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    border: 1px solid #333;
    background-color: #1a1a1a;
    border-radius: 3px;
}

.json-preview {
    background-color: #111;
    border: 1px solid #444;
    padding: 15px;
    font-family: monospace;
    font-size: 0.8em;
    white-space: pre-wrap;
    color: #999;
    border-radius: 3px;
    min-height: 300px;
}

.event-preview {
    max-height: 500px;
    overflow-y: auto;
}

/* =========================
   Templates & Quick Actions
   ========================= */
.templates {
    margin-bottom: 15px;
}

.template-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.template-button {
    padding: 6px 10px;
    background-color: #333;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 0.8em;
    border-radius: 3px;
    min-height: 32px;
}

.template-button:hover {
    background-color: #0085be;
}

/* =========================
   Image Modal & Media
   ========================= */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

.modal-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.modal-close {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #000;
    color: #fff;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
}

.modal-close:hover {
    background: #333;
}

.shared-image {
    max-width: 300px;
    max-height: 200px;
    border-radius: 5px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.shared-image:hover {
    opacity: 0.8;
}

.image-container {
    margin: 10px 0;
}

.file-container {
    margin: 10px 0;
    padding: 10px;
    background: #333;
    border-radius: 5px;
    border-left: 3px solid #5a5;
}

.file-link {
    color: #5a5;
    text-decoration: none;
}

.file-link:hover {
    color: #7c7;
}

.file-message {
    border-left: 3px solid #5a5;
}

/* =========================
   Event Kind Styling
   ========================= */
.kind-0 {
    display: none; /* Hide user metadata events */
}

.kind-5 {
    opacity: 0.6;
}

.kind-1 {
    border-left: 2px solid #666; /* Legacy text notes */
}

.kind-9 {
    border-left: 2px solid #0085be; /* Group chat messages */
}

/* =========================
   Responsive Design
   ========================= */
@media (max-width: 900px) {
    .event-form {
        grid-template-columns: 1fr;
    }
    
    .page-container {
        width: 95%;
        padding: 10px;
    }
    
    body {
        padding: 3px;
    }
    
    .controls input[type="text"] {
        width: 250px;
    }
    
    .filter-row {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
    
    .filter-row label {
        min-width: auto;
    }
}

@media (max-width: 600px) {
    .page-container.simple {
        width: 100%;
        padding: 0 10px;
    }

    .controls input[type="text"] {
        width: 100%;
        max-width: none;
        margin-right: 0;
        margin-bottom: 8px;
    }

    .message-input-container {
        padding: 6px;
    }

    .controls {
        padding: 6px;
    }

    .form-section {
        padding: 8px;
    }

    .submit-section {
        padding: 8px;
    }

    /* Better touch targets on mobile */
    button {
        min-height: 44px;
        padding: 8px 12px;
        font-size: 14px;
    }

    .button-small {
        min-height: 40px;
        padding: 8px 12px;
    }

    /* Stack filter buttons on mobile */
    .filter-buttons {
        flex-direction: column;
    }

    .template-buttons {
        flex-direction: column;
    }

    /* Stack message header items on mobile */
    .message-header,
    .event-header {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Better spacing for mobile forms */
    .tag-input-row {
        flex-direction: column;
        gap: 8px;
    }

    .tag-input-row input {
        width: 100%;
    }

    /* Larger text inputs on mobile - prevents iOS zoom */
    input[type="text"],
    input[type="password"],
    input[type="number"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px;
        padding: 10px;
    }

    /* Better modal on mobile */
    .modal-backdrop {
        max-width: 95%;
        max-height: 95%;
    }

    /* Stack controls on mobile */
    .controls {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .controls label {
        margin-bottom: 2px;
    }

    /* Improve readability */
    h1 {
        font-size: 1.3em;
    }

    h2 {
        font-size: 1.1em;
    }

    /* Full width buttons in controls on mobile */
    .controls button {
        width: 100%;
    }
}

@media (max-width: 400px) {
    .page-container {
        padding: 5px;
    }

    .page-container.simple {
        padding: 0 8px;
    }

    body {
        padding: 2px;
    }

    .input-controls {
        flex-direction: column;
    }

    .message-actions {
        opacity: 1; /* Always show on very small screens */
    }

    .event-metadata-row {
        flex-direction: column;
    }

    .event-metadata-label {
        min-width: auto;
        margin-bottom: 3px;
    }

    /* Compact spacing */
    .controls {
        padding: 8px;
    }

    .content-section,
    .form-section {
        padding: 8px;
    }

    /* Smaller font for very small screens */
    body {
        font-size: 14px;
    }

    .key-value,
    .json-preview,
    .event-json {
        font-size: 11px;
    }
}

/* =========================
   Identicon Styles
   ========================= */
.nostr-identicon {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.nostr-identicon svg {
    display: block;
    max-width: 100%;
    max-height: 100%;
    box-sizing: border-box;
}

/* Identicon in message contexts */
.message-identicon {
    margin-right: 4px;
    flex-shrink: 0;
    align-self: flex-start;
}

.event-identicon {
    margin-right: 6px;
}

.reply-identicon {
    margin: 0 4px;
    vertical-align: middle;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.reply-input-identicon {
    margin: 0 6px 0 4px;
    vertical-align: middle;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Size variants */
.nostr-identicon.small {
    width: 24px;
    height: 24px;
}

.nostr-identicon.medium {
    width: 32px;
    height: 32px;
}

.nostr-identicon.large {
    width: 48px;
    height: 48px;
}

/* Dark theme optimization */
@media (prefers-color-scheme: dark) {
    .nostr-identicon svg {
        background-color: #0a0a0a;
        border-color: #444;
    }
}

/* High contrast support */
@media (prefers-contrast: high) {
    .nostr-identicon svg {
        border-color: #666;
        background-color: #000;
    }
}

/* =========================
   Accessibility
   ========================= */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus indicators for keyboard navigation */
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #0085be;
    outline-offset: 2px;
}

/* =========================
   Emoji Reactions (NIP-25)
   ========================= */

/* Emoji picker popup */
.emoji-picker {
    position: fixed;
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.emoji-picker-content {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    max-width: 200px;
}

.emoji-option {
    background: transparent;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    min-height: 32px;
    min-width: 32px;
}

.emoji-option:hover {
    background: #0085be;
    border-color: #0085be;
}

/* Message reactions display */
.message-reactions {
    display: flex;
    gap: 4px;
    margin: 6px 0 4px 0;
    flex-wrap: wrap;
}

.reaction-badge {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #555;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s;
    color: #ccc;
    display: flex;
    align-items: center;
    gap: 3px;
    min-height: 24px;
    font-family: monospace;
}

.reaction-badge:hover {
    background: rgba(0, 133, 190, 0.2);
    border-color: #0085be;
    color: #fff;
}

.reaction-badge.user-reacted {
    background: rgba(0, 133, 190, 0.3);
    border-color: #0085be;
    color: #0085be;
}

.reaction-badge.user-reacted:hover {
    background: rgba(200, 50, 50, 0.3);
    border-color: #c55;
    color: #c55;
}

/* Mobile optimizations */
@media (max-width: 600px) {
    .emoji-picker {
        position: fixed;
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%);
        max-width: 90vw;
    }
    
    .emoji-picker-content {
        max-width: none;
        justify-content: center;
    }
    
    .emoji-option {
        min-height: 40px;
        min-width: 40px;
        font-size: 18px;
    }
    
    .reaction-badge {
        min-height: 28px;
        padding: 4px 10px;
        font-size: 0.9em;
    }
}

/* High contrast support */
@media (prefers-contrast: high) {
    body {
        background-color: #000;
        color: #fff;
    }
    
    .controls,
    .content-section,
    .form-section {
        border-color: #666;
    }
    
    input,
    select,
    textarea {
        border-color: #666;
    }
    
    .emoji-picker {
        border-color: #888;
        background: #000;
    }
    
    .emoji-option,
    .reaction-badge {
        border-color: #888;
    }
}
