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

:root {
    --primary-color: #2d5016;
    --secondary-color: #4a7c2c;
    --accent-color: #8b4513;
    --bg-color: #f5f5f0;
    --card-bg: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --border-color: #e0e0e0;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    --input-bg: #ffffff;
    --entry-bg: #f5f5f0;
    --notes-bg: #ffffff;
}

[data-theme="dark"] {
    --primary-color: #4a7c2c;
    --secondary-color: #5a9c3c;
    --accent-color: #c4703a;
    --bg-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #404040;
    --success-color: #2ecc71;
    --danger-color: #e74c3c;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
    --input-bg: #3a3a3a;
    --entry-bg: #353535;
    --notes-bg: #3a3a3a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease;
}

/* Ljust tema bakgrundsmönster */
:root body {
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.9)),
        url('data:image/svg+xml,<svg width="60" height="60" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h60v60H0z" fill="none"/><path d="M30 0L0 30l30 30 30-30L30 0zm0 5l25 25-25 25L5 30 30 5z" fill="%23e0e0e0" opacity="0.1"/></svg>');
}

/* Mörkt tema - ta bort bakgrundsmönster */
[data-theme="dark"] body {
    background-image: none;
    background-color: var(--bg-color);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 16px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.header-title {
    text-align: left;
}

.header-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.user-info {
    font-size: 0.9rem;
    opacity: 0.9;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

.btn-header {
    padding: 8px 16px;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s ease;
}

.btn-report {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-report:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.btn-logout {
    background-color: rgba(0, 0, 0, 0.2);
    color: white;
}

.btn-logout:hover {
    background-color: rgba(0, 0, 0, 0.3);
}

.btn-theme {
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 1.1rem;
    padding: 8px 12px;
}

.btn-theme:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

/* Smooth theme transition */
body,
.container,
header,
.add-entry-section,
.stats-section,
.entries-section,
.entry-card,
input,
select,
textarea {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.main-content {
    display: grid;
    gap: 30px;
}

.add-entry-section,
.stats-section,
.entries-section {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

label {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

input,
select,
textarea {
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    font-family: inherit;
    background-color: var(--input-bg);
    color: var(--text-primary);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(74, 124, 44, 0.1);
}

textarea {
    resize: vertical;
}

.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.btn-primary:hover {
    background: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    padding: 8px 16px;
    font-size: 0.9rem;
}

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

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

.stat-card {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.stat-label {
    font-size: 1rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.filter-controls {
    display: flex;
    gap: 10px;
}

.filter-select {
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    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='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

[data-theme="dark"] .filter-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='%23aaa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

.filter-select option {
    background-color: var(--input-bg);
    color: var(--text-primary);
}

.entries-list {
    display: grid;
    gap: 15px;
}

.entry-card {
    background: var(--entry-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    transition: all 0.3s ease;
}

.entry-card:hover {
    border-color: var(--secondary-color);
    box-shadow: var(--shadow);
    transform: translateX(5px);
}

.entry-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.entry-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary-color);
}

.entry-date {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.entry-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.detail-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.entry-notes {
    background: var(--notes-bg);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--accent-color);
    margin-bottom: 15px;
    color: var(--text-secondary);
}

.entry-actions {
    display: flex;
    justify-content: flex-end;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 100px;
    height: 100px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.success-message,
.error-message {
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 600;
}

.success-message {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Dark mode för meddelanden */
[data-theme="dark"] .success-message {
    background: #1e3a1e;
    color: #7dd87d;
    border: 1px solid #2d5a2d;
}

[data-theme="dark"] .error-message {
    background: #3a1e1e;
    color: #e88;
    border: 1px solid #5a2d2d;
}

/* Debug-fält */
#debugOutput {
    margin-top: 20px;
    padding: 10px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 5px;
    font-family: monospace;
    font-size: 12px;
    display: none;
    color: #856404;
}

[data-theme="dark"] #debugOutput {
    background: #3d3520;
    border-color: #6d5a10;
    color: #e0c060;
}

/* Select dropdown i dark mode */
[data-theme="dark"] select option {
    background-color: var(--input-bg);
    color: var(--text-primary);
}

/* Tablet och mindre */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header {
        padding: 20px 15px;
        border-radius: 10px;
        margin-bottom: 20px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .header-title {
        text-align: center;
    }

    .header-actions {
        width: 100%;
        align-items: center;
    }

    .header-buttons {
        width: 100%;
        justify-content: center;
    }

    .btn-header {
        flex: 1;
        text-align: center;
    }

    .add-entry-section,
    .stats-section,
    .entries-section {
        padding: 20px 15px;
        border-radius: 10px;
    }

    h2 {
        font-size: 1.4rem;
        margin-bottom: 15px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }

    .btn-primary {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-value {
        font-size: 2.2rem;
    }

    .stat-label {
        font-size: 0.85rem;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-select {
        width: 100%;
    }

    .entry-card {
        padding: 15px;
    }

    .entry-header {
        flex-direction: column;
        gap: 10px;
    }

    .entry-title {
        font-size: 1.1rem;
    }

    .entry-actions {
        width: 100%;
    }

    .entry-actions .btn-danger {
        width: 100%;
        text-align: center;
    }

    .entry-details {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .detail-label {
        font-size: 0.75rem;
    }

    .detail-value {
        font-size: 1rem;
    }
}

/* Mobil */
@media (max-width: 480px) {
    .container {
        padding: 8px;
    }

    header {
        padding: 15px 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    .add-entry-section,
    .stats-section,
    .entries-section {
        padding: 15px 12px;
    }

    h2 {
        font-size: 1.2rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .form-group {
        width: 100%;
    }

    .form-group.full-width {
        grid-column: 1;
    }

    label {
        font-size: 0.85rem;
        margin-bottom: 6px;
    }

    input,
    input[type="date"],
    input[type="time"],
    input[type="text"],
    input[type="number"],
    select,
    textarea {
        padding: 12px;
        font-size: 16px; /* Förhindrar zoom på iOS */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    input[type="date"],
    input[type="time"] {
        min-height: 48px;
    }

    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='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 36px;
    }

    [data-theme="dark"] 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='%23aaa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    }

    textarea {
        min-height: 80px;
    }

    .btn-primary {
        padding: 14px 20px;
        font-size: 1rem;
    }

    .stat-value {
        font-size: 1.8rem;
    }

    .entry-details {
        grid-template-columns: 1fr;
    }

    .success-message,
    .error-message {
        padding: 12px 15px;
        font-size: 0.9rem;
    }

    #debugOutput {
        font-size: 11px;
        padding: 8px;
        word-break: break-word;
    }
}

/* ========================================
   BILDUPPLADDNING OCH VISNING
======================================== */

/* Filinput styling */
.image-upload-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

input[type="file"] {
    padding: 10px;
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-bg);
    color: var(--text-color);
    cursor: pointer;
    transition: border-color 0.3s ease;
}

input[type="file"]:hover {
    border-color: var(--primary-color);
}

input[type="file"]::file-selector-button {
    padding: 8px 16px;
    margin-right: 10px;
    border: none;
    border-radius: 4px;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.3s ease;
}

input[type="file"]::file-selector-button:hover {
    background: var(--primary-dark);
}

.form-help {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 4px;
}

/* Bildförhandsvisning */
.image-preview {
    margin-top: 5px;
}

.preview-container {
    position: relative;
    display: inline-block;
    max-width: 200px;
}

.preview-container img {
    max-width: 100%;
    max-height: 150px;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    object-fit: contain;
}

.btn-remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: var(--danger-color);
    color: white;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.btn-remove-image:hover {
    transform: scale(1.1);
}

/* Bild i fångstkortet */
.entry-image {
    margin: 10px 0;
    text-align: center;
}

.entry-image img {
    max-width: 100%;
    max-height: 250px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    object-fit: contain;
}

.entry-image img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.entry-card.has-image {
    /* Lite extra padding för kort med bilder */
}

/* Bildmodal för fullstorlek */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
}

.image-modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    text-align: center;
}

.image-modal-content img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--border-radius);
    object-fit: contain;
}

.image-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    font-size: 30px;
    color: white;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.image-modal-close:hover {
    transform: scale(1.2);
}

.image-modal-title {
    color: white;
    margin-top: 15px;
    font-size: 1.1rem;
}

/* Responsiv bildhantering */
@media (max-width: 768px) {
    .preview-container img {
        max-height: 120px;
    }

    .entry-image img {
        max-height: 200px;
    }

    .image-modal-content img {
        max-height: 70vh;
    }
}

@media (max-width: 480px) {
    .preview-container img {
        max-height: 100px;
    }

    .entry-image img {
        max-height: 150px;
    }

    input[type="file"]::file-selector-button {
        padding: 6px 12px;
        font-size: 0.9rem;
    }
}

/* ========================================
   GPS-LÄNKAR
======================================== */

.gps-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(45, 80, 22, 0.1);
    transition: all 0.2s ease;
}

.gps-link:hover {
    background: var(--primary-color);
    color: white;
    text-decoration: none;
}

[data-theme="dark"] .gps-link {
    background: rgba(74, 124, 44, 0.2);
    color: var(--primary-light);
}

[data-theme="dark"] .gps-link:hover {
    background: var(--primary-color);
    color: white;
}
