:root {
    --primary-color: #4a90e2;
    --secondary-color: #50c878;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --bg-color: #f5f7fa;
    --text-color: #2c3e50;
    --border-color: #dfe6e9;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    padding: 20px;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 30px;
}

.hidden {
    display: none !important;
}

/* Header */
.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border-color);
}

.app-title h1 {
    color: var(--primary-color);
    font-size: 1.5em;
}

.app-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.annotator-name {
    font-weight: 600;
}

.progress-text {
    font-size: 0.9em;
    color: #7f8c8d;
}

h3 {
    color: var(--text-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.hint-inline {
    font-weight: 400;
    font-size: 0.8em;
    color: #7f8c8d;
}

section {
    margin-bottom: 24px;
}

/* Help panel */
.help-panel {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 24px;
}

.help-panel > summary {
    cursor: pointer;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--primary-color);
}

.help-body {
    padding: 0 16px 16px;
    font-size: 0.9em;
}

.help-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.help-table th,
.help-table td {
    border: 1px solid var(--border-color);
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}

.help-table th {
    background: #eef2f7;
}

.help-body code {
    background: #eef2f7;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.92em;
}

.help-rules {
    margin: 8px 0 0 18px;
}

.help-rules li {
    margin-bottom: 4px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #357abd;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #7f8c8d;
}

.btn-warning {
    background-color: var(--warning-color);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background-color: #d9890c;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
    padding: 5px 10px;
    font-size: 0.9em;
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Label palette */
.label-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.label-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    user-select: none;
}

.label-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.label-item.selected {
    border: 2px solid var(--text-color);
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--text-color);
}

.label-key {
    background: rgba(255, 255, 255, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

/* Item text */
.text-content {
    padding: 24px 20px;
    background: var(--bg-color);
    border-radius: 8px;
    font-size: 1.25em;
    line-height: 2.2;
    min-height: 90px;
    user-select: text;
    cursor: text;
    white-space: pre-wrap;
    word-break: break-word;
}

.text-content::selection,
.text-content *::selection {
    background: rgba(74, 144, 226, 0.35);
}

.entity-highlight {
    position: relative;
    padding: 2px 2px;
    border-radius: 3px;
}

.entity-label-tag {
    position: absolute;
    top: -16px;
    left: 0;
    font-size: 0.55em;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: bold;
    white-space: nowrap;
    color: white;
    user-select: none;
    pointer-events: none;
}

/* Spans list */
.entities-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.empty-hint {
    color: #7f8c8d;
    font-style: italic;
}

.entity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-color);
    border-radius: 6px;
    border-left: 4px solid;
}

.entity-info {
    flex: 1;
}

.entity-text {
    font-weight: 500;
    margin-bottom: 4px;
}

.entity-meta {
    font-size: 0.85em;
    color: #7f8c8d;
}

/* Flag + note */
.meta-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flag-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
}

.note-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95em;
    font-family: inherit;
    resize: vertical;
}

/* Action controls */
.action-controls {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.action-controls .btn {
    flex: 1;
}

#saveNextBtn {
    flex: 1.4;
}

/* Done view */
.done-view {
    text-align: center;
    padding: 40px 20px;
}

.done-view h2 {
    color: var(--secondary-color);
    margin-bottom: 16px;
}

.done-progress {
    font-weight: 600;
    margin: 12px 0;
}

.done-view .hint {
    color: #7f8c8d;
    font-size: 0.9em;
    margin: 12px 0 20px;
}

/* Toasts */
.toasts {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    align-items: center;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success { background: var(--secondary-color); }
.toast-error { background: var(--danger-color); }
.toast-info { background: var(--primary-color); }

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .app-meta {
        align-items: flex-start;
    }

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

    .text-content {
        font-size: 1.1em;
    }
}

/* Login (M3) */
.btn-small {
    padding: 6px 12px;
    font-size: 0.85em;
}

.login-view {
    max-width: 420px;
    margin: 40px auto;
    text-align: center;
}

.login-view h2 {
    color: var(--primary-color);
    margin-bottom: 8px;
}

.login-hint {
    color: #7f8c8d;
    font-size: 0.9em;
    margin-bottom: 24px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9em;
}

.login-field input {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1em;
}

.login-form .btn {
    margin-top: 8px;
}
