/* ========================================
   CSS Variables
   ======================================== */
:root {
    --primary: #6C3FA0;
    --primary-hover: #8B5DC8;
    --primary-light: #F5F0FF;
    --bg: #F8F8FA;
    --bg-white: #FFFFFF;
    --text: #1A1A2E;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --border: #E5E7EB;
    --border-light: #F3F4F6;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --transition: 0.2s ease;

    /* Status Colors */
    --status-new: #E0E0E0;
    --status-email-searched: #E3F2FD;
    --status-requested: #FFF9C4;
    --status-reminder: #FFE0B2;
    --status-thanked-with: #C8E6C9;
    --status-thanked-without: #C8E6C9;
    --status-no-reply: #FFCDD2;
}

.hidden {
    display: none !important;
}

/* ========================================
   Reset & Base
   ======================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-width: 1200px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--border-light);
}

::-webkit-scrollbar-thumb {
    background: #C4C4C4;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #A0A0A0;
}

/* ========================================
   Typography
   ======================================== */
h1, h2, h3 {
    font-weight: 600;
    color: var(--text);
}

/* ========================================
   Form Elements
   ======================================== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-white);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 63, 160, 0.12);
}

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

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

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    gap: 6px;
    line-height: 1.4;
}

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

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

.btn-secondary {
    background: var(--bg-white);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
    border-color: #D1D5DB;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--border-light);
    color: var(--text);
}

.btn-danger {
    background: transparent;
    color: #DC2626;
}

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

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* ========================================
   Login Page
   ======================================== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    width: 400px;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-error {
    background: #FEF2F2;
    color: #DC2626;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 20px;
    border: 1px solid #FECACA;
}

/* ========================================
   Header
   ======================================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

/* ========================================
   Tab Navigation
   ======================================== */
.tab-nav {
    display: flex;
    gap: 0;
    padding: 0 32px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ========================================
   Tab Content
   ======================================== */
.tab-content {
    display: none;
    padding: 24px 32px;
}

.tab-content.active {
    display: block;
}

/* ========================================
   Toolbar
   ======================================== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
}

.toolbar-left {
    flex: 1;
    max-width: 320px;
}

.toolbar-right {
    display: flex;
    gap: 8px;
}

.search-input {
    width: 100%;
    padding: 8px 14px;
    padding-left: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

/* ========================================
   Table
   ======================================== */
.table-wrapper {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: visible;
}

.entries-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.entries-table thead {
    background: var(--border-light);
}

.entries-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    user-select: none;
    border-bottom: 1px solid var(--border);
}

.entries-table th.sortable {
    cursor: pointer;
}

.entries-table th.sortable:hover {
    color: var(--primary);
}

.sort-icon {
    display: inline-block;
    width: 12px;
    margin-left: 2px;
    font-size: 10px;
    vertical-align: middle;
}

.entries-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    max-width: 240px;
}

.entries-table tbody tr {
    transition: background var(--transition);
}

.entries-table tbody tr:hover {
    background: var(--primary-light);
}

.col-checkbox {
    width: 40px;
    text-align: center;
}

.col-checkbox input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--primary);
}

.col-link {
    min-width: 200px;
}

.col-email {
    min-width: 180px;
}

.col-anrede {
    width: 80px;
}

.col-name {
    min-width: 140px;
}

.col-status {
    width: 160px;
}

.col-days {
    width: 60px;
    text-align: center;
}

.col-created {
    width: 100px;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 12px;
}

.col-notes {
    min-width: 160px;
}

.col-actions {
    width: 100px;
    text-align: center;
}

/* ========================================
   Inline Editing
   ======================================== */
.cell-editable {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-editable:hover {
    background: rgba(108, 63, 160, 0.06);
}

.cell-editable.editing {
    padding: 0;
}

.inline-input,
.inline-textarea,
.inline-select {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    box-shadow: 0 0 0 2px rgba(108, 63, 160, 0.15);
    background: var(--bg-white);
}

.inline-textarea {
    resize: vertical;
    min-height: 50px;
}

/* ========================================
   Link Column
   ======================================== */
.link-external {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
    word-break: break-all;
}

.link-external:hover {
    text-decoration: underline;
}

/* ========================================
   Status Badge
   ======================================== */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.5;
}

.status-badge.status-new {
    background: var(--status-new);
    color: #424242;
}

.status-badge.status-email-searched {
    background: var(--status-email-searched);
    color: #1565C0;
}

.status-badge.status-requested {
    background: var(--status-requested);
    color: #F57F17;
}

.status-badge.status-reminder {
    background: var(--status-reminder);
    color: #E65100;
}

.status-badge.status-thanked-with {
    background: var(--status-thanked-with);
    color: #2E7D32;
}

.status-badge.status-thanked-without {
    background: var(--status-thanked-without);
    color: #2E7D32;
}

.status-badge.status-no-reply {
    background: var(--status-no-reply);
    color: #C62828;
}

/* ========================================
   Days Warning
   ======================================== */
.days-warning {
    color: #DC2626;
    font-weight: 600;
}

/* ========================================
   Actions Dropdown
   ======================================== */
.actions-wrapper {
    position: relative;
}

.actions-trigger {
    padding: 4px 10px;
    font-size: 12px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.actions-trigger:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.actions-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 200px;
    z-index: 500;
    overflow: hidden;
}

.actions-menu.open {
    display: block;
}

.actions-menu button {
    display: block;
    width: 100%;
    padding: 8px 14px;
    text-align: left;
    background: none;
    border: none;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    transition: background var(--transition);
}

.actions-menu button:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.actions-menu button.action-delete {
    color: #DC2626;
}

.actions-menu button.action-delete:hover {
    background: #FEF2F2;
}

.actions-menu .menu-divider {
    height: 1px;
    background: var(--border-light);
    margin: 4px 0;
}

/* ========================================
   Table Empty State
   ======================================== */
.table-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ========================================
   Templates
   ======================================== */
.templates-container {
    max-width: 800px;
}

.template-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.template-card h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--primary);
}

.template-placeholders {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-family: monospace;
}

.section-title {
    font-size: 18px;
    margin-bottom: 16px;
    margin-top: 8px;
}

/* ========================================
   Settings
   ======================================== */
.settings-container {
    max-width: 600px;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.status-item {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}

.status-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.status-value {
    font-size: 14px;
    font-weight: 500;
}

.status-value.ok {
    color: #16A34A;
}

.status-value.error {
    color: #DC2626;
}

.settings-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

/* ========================================
   Modals
   ======================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

.modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 460px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.2s ease;
}

.modal-wide {
    width: 640px;
}

.modal-small {
    width: 400px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--border-light);
    color: var(--text);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 24px 20px;
}

.hint-text {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ========================================
   History
   ======================================== */
.history-entry {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

.history-entry:last-child {
    border-bottom: none;
}

.history-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.history-action {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 2px;
}

.history-subject {
    font-size: 13px;
    color: var(--text-secondary);
}

.history-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 14px;
}

/* ========================================
   Toast Notifications
   ======================================== */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.25s ease, fadeOut 0.3s ease 2.7s forwards;
    max-width: 360px;
}

.toast-success {
    background: #16A34A;
    color: #FFFFFF;
}

.toast-error {
    background: #DC2626;
    color: #FFFFFF;
}

.toast-info {
    background: var(--primary);
    color: #FFFFFF;
}

/* ========================================
   Animations
   ======================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
