/* ============================================================
   Igelprotokoll - Responsive CSS (Mobile-First)
   ============================================================ */

:root {
    --primary: #2d5016;
    --primary-light: #4a7c2e;
    --primary-dark: #1a3009;
    --primary-bg: #f0f5ec;
    --accent: #d4a017;
    --accent-light: #f5d76e;
    --danger: #c0392b;
    --danger-light: #f8d7da;
    --success: #27ae60;
    --success-light: #d4edda;
    --warning: #f39c12;
    --warning-light: #fff3cd;
    --info: #2980b9;
    --info-light: #d1ecf1;
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #404040;
    --gray-800: #262626;
    --text: #1a1a1a;
    --text-light: #525252;
    --bg: #ffffff;
    --bg-alt: #f5f5f5;
    --border: #e5e5e5;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-sm: 4px;
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --transition: 0.2s ease;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg-alt);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
table { border-collapse: collapse; width: 100%; }

/* Utility */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-light); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ============================================================
   Auth Screen
   ============================================================ */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-container {
    width: 100%;
    max-width: 420px;
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem 1.5rem;
}
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo h1 { font-size: 1.5rem; color: var(--primary); margin-top: 0.25rem; }
.logo-icon { font-size: 3rem; }
.logo-icon-sm { font-size: 1.75rem; }
.subtitle { color: var(--text-light); font-size: 0.875rem; }

.auth-tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-light);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.form-section-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0.5rem 0;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
}

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="tel"],
select, textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    transition: border-color var(--transition);
    -webkit-appearance: none;
    appearance: none;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45, 80, 22, 0.1);
}
textarea { resize: vertical; min-height: 80px; }
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23525252' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.checkbox-group input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--primary);
}

.error-msg {
    background: var(--danger-light);
    color: var(--danger);
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary { background: var(--gray-100); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #219a52; }
.btn-sm { padding: 0.3rem 0.625rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1.25rem;
    color: var(--text);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.btn-icon:hover { background: var(--gray-100); }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 0.75rem;
    z-index: 100;
    box-shadow: var(--shadow);
}
.topbar-title { font-size: 1.125rem; font-weight: 700; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }
.topbar .btn-icon { color: #fff; }
.topbar .btn-icon:hover { background: rgba(255,255,255,0.15); }

.hamburger {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    position: relative;
}
.hamburger::before, .hamburger::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: #fff;
    left: 0;
}
.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

.user-badge {
    font-size: 0.8125rem;
    background: rgba(255,255,255,0.15);
    padding: 0.25rem 0.625rem;
    border-radius: 1rem;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform var(--transition);
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar-height);
    background: rgba(0,0,0,0.3);
    z-index: 80;
}
.sidebar-overlay.active { display: block; }

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.sidebar-header strong { display: block; font-size: 0.875rem; }
.sidebar-header small { color: var(--text-light); font-size: 0.75rem; }

.nav-list { list-style: none; padding: 0.5rem 0; flex: 1; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 0;
    transition: var(--transition);
}
.nav-link:hover { background: var(--primary-bg); }
.nav-link.active { background: var(--primary-bg); color: var(--primary); font-weight: 700; }
.nav-icon { font-size: 1.1rem; width: 1.5rem; text-align: center; }
.nav-divider { height: 1px; background: var(--border); margin: 0.5rem 1rem; }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 0.5rem 0;
}

/* ============================================================
   Content
   ============================================================ */
.content {
    margin-top: var(--topbar-height);
    padding: 1rem;
    min-height: calc(100vh - var(--topbar-height));
}

/* ============================================================
   Page Header
   ============================================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.page-header h2 { font-size: 1.25rem; }

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 0.9375rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-body { padding: 1rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    text-align: center;
}
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.8125rem; color: var(--text-light); margin-top: 0.25rem; }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { min-width: 600px; }
.data-table th {
    background: var(--gray-50);
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    vertical-align: top;
}
.data-table tr:hover { background: var(--gray-50); }
.data-table tr { cursor: pointer; }

/* ============================================================
   Badges / Status
   ============================================================ */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}
.badge-active { background: var(--success-light); color: var(--success); }
.badge-released { background: var(--info-light); color: var(--info); }
.badge-deceased { background: var(--gray-200); color: var(--gray-600); }
.badge-hibernating { background: var(--warning-light); color: #856404; }
.badge-draft { background: var(--gray-200); color: var(--gray-600); }
.badge-sent { background: var(--info-light); color: var(--info); }
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-overdue { background: var(--danger-light); color: var(--danger); }

.gender-icon { font-size: 1rem; }

/* ============================================================
   Hedgehog Detail
   ============================================================ */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}
.detail-item { display: flex; flex-direction: column; }
.detail-label { font-size: 0.75rem; font-weight: 700; color: var(--text-light); text-transform: uppercase; }
.detail-value { font-size: 0.9375rem; }

.weight-chart-container {
    width: 100%;
    overflow-x: auto;
    margin: 1rem 0;
}
.weight-chart {
    width: 100%;
    min-width: 300px;
    height: 200px;
    position: relative;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
}

/* ============================================================
   Audit / History
   ============================================================ */
.audit-list { list-style: none; }
.audit-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.audit-item:last-child { border: none; }
.audit-meta { color: var(--text-light); font-size: 0.75rem; margin-bottom: 0.25rem; }
.audit-action { font-weight: 600; }
.audit-diff { margin-top: 0.5rem; }
.audit-diff .field-change {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8125rem;
    padding: 0.15rem 0;
}
.field-name { font-weight: 600; min-width: 120px; }
.field-old { color: var(--danger); text-decoration: line-through; }
.field-new { color: var(--success); }

/* ============================================================
   Search / Filter Bar
   ============================================================ */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.filter-bar input, .filter-bar select { flex: 1; min-width: 120px; }
.search-input {
    position: relative;
}

/* ============================================================
   Modal
   ============================================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
    padding-top: calc(var(--topbar-height) + 1rem);
}
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: -1;
}
.modal-dialog {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
    max-height: calc(100vh - var(--topbar-height) - 2rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.125rem; }
.modal-close { font-size: 1.5rem; line-height: 1; }
.modal-body { padding: 1rem; overflow-y: auto; flex: 1; }
.modal-body .form-group { margin-bottom: 0.75rem; }
.modal-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ============================================================
   Toast Notifications
   ============================================================ */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 90vw;
}
.toast {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 400px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--info); color: #fff; }

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

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-light);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state p { margin-bottom: 1rem; }

/* ============================================================
   Loading Spinner
   ============================================================ */
.spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.loading-page { display: flex; justify-content: center; padding: 3rem; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Responsive: Tablet
   ============================================================ */
@media (min-width: 768px) {
    .sidebar {
        transform: translateX(0);
    }
    .content {
        margin-left: var(--sidebar-width);
        padding: 1.5rem;
    }
    #menu-toggle { display: none; }
    .sidebar-overlay { display: none !important; }

    .detail-grid {
        grid-template-columns: 1fr 1fr;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .modal-dialog {
        max-width: 700px;
    }
}

/* ============================================================
   Responsive: Desktop
   ============================================================ */
@media (min-width: 1024px) {
    .content { padding: 2rem; }

    .detail-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }
}

/* ============================================================
   Autocomplete / Suggestions
   ============================================================ */
.autocomplete-wrap {
    position: relative;
}
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    max-height: 180px;
    overflow-y: auto;
    box-shadow: var(--shadow);
}
.autocomplete-item {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100);
}
.autocomplete-item:hover, .autocomplete-item.active {
    background: var(--primary-bg);
    color: var(--primary);
}
.autocomplete-item:last-child { border-bottom: none; }

/* ============================================================
   Dynamic Medication Fields
   ============================================================ */
.med-entry {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
}
.med-entry .form-group { margin-bottom: 0; }
.btn-remove-med {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--danger);
    font-size: 1.25rem;
    padding: 0.4rem;
    line-height: 1;
    border-radius: var(--radius-sm);
    align-self: end;
    margin-bottom: 0.3rem;
}
.btn-remove-med:hover { background: var(--danger-light); }
#add-med-btn { margin-top: 0.25rem; }

/* ============================================================
   Print
   ============================================================ */
@media print {
    .topbar, .sidebar, .sidebar-overlay, #menu-toggle,
    .btn, .filter-bar, .toast-container, .modal { display: none !important; }
    .content { margin: 0; padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}
